latex usage details

1. Language selection

\usepackage[english]{babel}        % This line of code uses babelthe macro package and sets the document language to English.

        babelThe macro package provides support for multiple languages, including language-specific hyphenation, date formats, punctuation, etc. By setting different language options, you can process content in different languages ​​in the same document.
In this example, English is set as the document language, which may affect the date display format, font style, and some language-specific commands and environments.

\usepackage[UTF8]{ctex}        % Set the document as a Chinese document, you can use ctexthe macro package. And set the encoding to UTF8 to support Chinese input and output

        But you need to make sure that the macro package is installed in your LaTeX distribution ctex. In this way, when you compile, the Chinese document will be generated correctly.

2. Page settings

\usepackage[letterpaper,top=2cm,bottom=2cm,left=3cm,right=3cm,

marginparwidth=1.75cm]{geometry}

%This line of code uses the `geometry` macro package and sets the page size and margins.

- `letterpaper`: Set the paper size to Letter paper size, which is one of the commonly used paper sizes in the United States. You can also choose other paper sizes, such as A4, A5, etc.
- `top=2cm`: Set the top margin of the page to 2cm.
- `bottom=2cm`: Set the bottom margin of the page to 2cm.
- `left=3cm`: Set the left margin of the page to 3cm.
- `right=3cm`: Set the right margin of the page to 3cm.
- `marginparwidth=1.75cm`: Set the width of the margin (marginpar) to 1.75cm.

By adjusting these parameters, you can customize the page's dimensions and margins to suit your needs. Note that the unit of these parameters defaults to inches. If you need to use other units, you can add the corresponding unit after the value, such as `2cm` for 2 centimeters, and `5mm` for 5 millimeters.

3. Mathematical formulas and mathematical typesetting

1. Macro packages involved

\usepackage{amsmath}
\usepackage{graphicx}
\usepackage[colorlinks=true, allcolors=blue]{hyperref}

%This code loads three macro packages: `amsmath`, `graphicx` and `hyperref`. `hyperref` is loaded with the options `colorlinks=true, allcolors=blue` set. This means that all types of links will appear with blue text instead of the default red frame. At the same time, the link will have a clickable hyperlink effect.

- The `amsmath` macro package provides a series of commands and environments for mathematical typesetting , which can help write mathematical formulas and equations more conveniently. It is one of the most commonly used mathematical macro packages in LaTeX.

- The `graphicx` package allows you to insert and manipulate graphics, such as picture files. It provides the `\includegraphics` command, making it easy to insert images into the document.

- The `hyperref` package allows you to add hyperlinks to documents and generate interactive PDF documents. By setting options, you can define the style of the link, including color, border, etc.

2. The formula appears as it is

Latex will strictly standardize the various input formats, causing the original style to be lost. At this time, you can use "$...$" to maintain its original style. One $ is an inline formula, and two $$ is a line break formula.

You must learn to use $. Many symbols cannot be displayed in latex, such as "~" or ">". In this case, just add $ on both sides.

For example:

 

3. Automatic formula numbering and calling formula numbering

The $L_p$ distance between $x_i$ and $x_j$ is defined 
as formula(\ref{eqn:b}):

\begin{equation}

L_p(x_i, x_j) = \left(\sum_{k=1}^{n} |x_{i}^{(k)} - 
x_{j}^{(k)}|^p\right)^{\frac{1}{p}}

\label{eqn:b}
\end{equation}

As shown in FIG:

\begin{equation}

official

\end{equation}
Use the command \label{eq:AAA} or \label{eqn:AAA} for numbering. The numbering command should be written in

\begin{equation} and \end{equation} any direct position.

When calling this formula, just write (\ref{eq:AAA}) directly. AAA is the label name given to the label, and each formula should have its own unique label name.

For example:

Shown as:

 

4. Greek alphabet

Greek letters are particularly common in mathematical formulas. But how to type it in letex?

$\alpha$ will display α, that is, enter the corresponding English pronunciation between the two $, and add "\" before the pronunciation.

uppercase greek letters lowercase greek letters pronounce
Alpha A a alpha alpha
Beta B b beta Beta
Gamma C c gamma gamma
Delta D d delta delta
Epsilon E e epsilon Epsilon
Zeta Z g zeta cut tower
And H the and ita
Theta Th i theta west tower
Iota I i iota Jota
Kappa K K kappa Kappa
Lambda L l lambda Lambda
In M m in Miao
Not N n not New
Xi X X xi Kersey
Omicron O o omicron Omicron
Pi Pi Pi pi group
Rho P r rho soft
Sigma S p sigma Sigma
Yes T t yes set
Upsilon Y u upsilon Upsilon
Phi Phi Phi phi Fiji
Chi X h chi happiness
Psi Ps p psi Pusey
Omega Oh oh omega Omega

4. abstract

\begin{abstract}
        Your abstract.
\end{abstract}

Effect:

 5. Create a link

`\href` is a LaTeX command used to create links. It allows inserting hyperlinks into documents, enabling readers to click on the link and jump to a specified web page or file.

The syntax is as follows:
\href{URL}{text}

Among them, `URL` is the target address of the link, which can be the URL of a website or the path of a local file. `Text` is the clickable text displayed in the document. The content in {URL} will not be displayed in the article. Only the text content in {text} will appear in the article, and it will be blue. Click to jump.

Example:
\href{https://www.overleaf.com/learn}{Help Library}

This will create a link in the document that reads "Help Library" and when the reader clicks on the link, it will jump to https://www.overleaf.com/learn.

For example:

The URL will not be displayed in the documentation, but clicking on the label "help library" will jump to it:

6. Font 

In LaTeX, you can use different commands to set fonts. The following are some commonly used command examples for setting fonts:

1. Set the font shape:
   - `\textup{}`: upright font (default shape).
   - `\textit{}`: italic font.
   - `\textsl{}`: Italic font.
   - `\textsc{}`: small caps font.

2. Set the font series (font series), pay attention to the format that distinguishes the font size :
   - `\textmd{}`: medium weight (default series).
   - `\textbf{}`: Bold.

3. Set a specific font size, format {\tiny the part where you want to change the font size}:
   - `\tiny`: extremely small size.
   - `\scriptsize`: Extra small size.
   - `\footnotesize`: footnote number.
   - `\small`: small size.
   - `\normalsize`: normal size (default size).
   - `\large`: Large size. % Lowercase L
   - `\Large`: larger size.
   - `\LARGE`: larger size.
   - `\huge`: Huge number.
   - `\Huge`: Extra large size.

Here is an example showing how to set the font using these commands:

This is some \textbf{bold text} and \textit{italic text}.

{\large This is some larger text.}   % Large, only the fonts in {} will change. If {} is not added, all the fonts behind will change.

\textsc{This is some small caps text.} %Small caps font.

In this example, different commands are used to style and size the font. You can set the font according to your needs by using the appropriate command in the corresponding text part.

7. Create a three-line table 

\documentclass{article}
\usepackage{array}

\begin{document}
\begin{table}[h]
\centering
\caption{Pseudocode for KNN Algorithm}
\label{tab:pseudocode}
\begin{tabular}{>{\ttfamily}r l}
\hline
\textbf{Line} & \textbf{Code} \\
\hline
1 & function KNN(inX, dataSet, labels, k) \\
2 & \quad dataSetSize = dataSet.shape[0] \\
3 & \quad diffMat = tile(inX, (dataSetSize, 1)) - dataSet \\
4 & \quad sqDiffMat = diffMat^2 \\
5 & \quad sqDistance = sqDiffMat.sum(axis=1) \\
6 & \quad distances = sqDistance^0.5 \\
7 & \quad sortedDistIndicies = distances.argsort() \\
8 & \quad classCount = \{\} \\
9 & \quad for i in range(k): \\
10 & \quad \quad voteIlabel = labels[sortedDistIndicies[i]] \\
11 & \quad \quad classCount[voteIlabel] = classCount.get(voteIlabel, 0) + 1 \\
12 & \quad sortedClassCount = sorted(classCount.items(), key=operator.itemgetter(1), reverse=True) \\
13 & \quad return sortedClassCount[0][0] \\
14 & end function \\
\hline
\end{tabular}
\end{table}
\end{document}

Effect display:
analyze the code line by line:

\usepackage{float}
\usepackage{array}   % Imports two packages, `float` and `array`, which provide functions related to floating point numbers and arrays. These functions may be used in subsequent code.


\begin{table}[h]
\centering        % 命令居中对齐表格
\caption{Pseudocode for KNN Algorithm}        %命令设置表格的标题
\label{tab:pseudocode}        %  为表格设置一个标签,以便在其他位置引用该表格
\begin{tabular}{>{\ttfamily}r l}        %  指定列格式为 `>{\ttfamily}r l`。其中 `>{\ttfamily}` 是一个修饰符,表示该列使用等宽字体(typewriter font)显示,`r` 和 `l` 表示该列的对齐方式为右对齐和左对齐。


\hline
\textbf{Line} & \textbf{Code} \\
\hline        % 绘制表格的横线
伪代码
\hline        %  再次绘制一条横线
\end{tabular}        %  结束表格的定义
\end{table}        %  结束表格环境

8、细小知识点 

1、换行

1. 在需要换行的位置使用 `\\` 或者 `\newline` 命令表示手动换行。例如:
这是第一行。\\  这是第二行。

则会显示为:

这是第一行。

这是第二行。

2. 使用空行:在两行之间插入一个或多个空行,表示换行。示例代码如下:

这是第一行。

(此行为空)

这是第二行。

则会显示为:

这是第一行。

这是第二行。

请注意,LaTeX 默认会自动调整段落的行距以适应页面,所以在正文中不需要手动插入换行命令。如果您想要更精确地控制换行和段落间距,可以使用额外的包或命令,如 `setspace` 宏包提供的命令 `\setstretch` 来设置行距。

2、空格:

手动敲空格是没有用的,需要使用:\quad 是空一个格,\qquad是空两个格。……  \qqquad 

3、一句话前面加“·”:

在 LaTeX 中,在一句话前面加上圆点(·)可以使用 `\textperiodcentered` 命令或者直接输入 UTF-8 编码。

方法一:使用 `\textperiodcentered` 命令
\textperiodcentered\ 好好学习,天天向上。

方法二:使用 UTF-8 编码
\symbol{183}\ 好好学习,天天向上。
或者直接输入圆点字符(·):
·\ 好好学习,天天向上。

上述方法都会在句子前面添加一个圆点(·)。
注意:在TeX文档中,请确保使用的编码格式支持UTF-8,否则可能会显示错误的符号。

方法三:本身就有这一按钮,在菜单栏上找一找即可。

4、段落缩进:

取消缩进:

要让一段英文段落开头不空两行,在 LaTeX 中可以使用 `\noindent` 命令。`\noindent` 命令用于取消段落的缩进,使得段落的首行与正文的左边界对齐。

以下是一个示例:
\noindent This is the first line of the paragraph. It starts at the leftmost margin of the page.

This is the second line of the paragraph. It continues from the leftmost margin without any indentation.

在上述示例中,`\noindent` 命令被用来取消首行的缩进,使得段落从页边开始。这样就能够实现段落开头不空两行的效果。

请注意,如果您希望对整个文档禁用所有段落的缩进,您可以在导言区(preamble)使用 `\setlength{\parindent}{0pt}` 命令。这将取消所有段落的缩进,默认值为零。

Guess you like

Origin blog.csdn.net/weixin_48060069/article/details/132377869