# Latex Note

Created on Thu, 05 Dec 2019, 08:07PM

Last changed on Tue, 25 Feb 2020, 12:44AM

## 基础公式

### 基础数学公式

*LaTeX*的数学公式主要有两种，即行内公式（Inline Formulas）和块级公式（Display Formulas）。行内公式内嵌于正文文本中间，与正文文字行高相等；块级公式则单独成行。

#### 行内公式

用`$...$`符号包围的*LaTeX*代码：

```latex
这样的代码可以生成如$$x^n+y^n=z^n$$这样的行内公式。
```

> eg. 这样的代码可以生成如$$x^n+y^n=z^n$$这样的行内公式。

#### 块级公式

用`$$...$$`符号包围的*LaTeX*代码：

```latex
这样的代码可以生成如$$x^n+y^n=z^n$$这样的块级公式。
```

> eg. 这样的代码可以生成如
>
> $$x^n+y^n=z^n$$
>
> **这样的块级公式。**

#### 块级公式的编号

直接使用块级代码`$$x^n+y^n=z^n$$`不会生成编号，而使用`\tag{...}`标签就可以生成对应的编号。

```latex
这样的代码可以生成如`$$x^n+y^n=z^n \tag{1.1}$$`的编号块级公式。
```

> eg. 这样的代码可以生成如

$$x^n+y^n=z^n \tag{1.1}$$

> 的编号块级公式。

{% hint style="info" %}
除了手动编号之外*LaTeX*还支持对公式的自动编号，对于需要自动编号的公式，需要使用`\begin{equation}...\end{equation}`将代码快包围起来。
{% endhint %}

```latex
这样的代码可以生成如$$\begin{equation}x^n+y^n=z^n\end{equation}$$的自动编号块级公式。
```

> eg. 这样的代码可以生成如

$$
\begin{equation} x^n+y^n=z^n \end{equation}
$$

> 的自动编号块级公式。

因为自动编号的代码较为复杂，而且不易扩展，所以不太建议使用自动编号，手动编号更易维护。

公式引用时候可以直接用`$编号$`即可。 对于`$$a^2+b^2=c^2 \tag {1.2}$$`由公式`$(1.2)$`即可得到结论。

> eg. 对于

$$a^2+b^2=c^2 \tag {1.2}$$

> 由公式$$(1.2)$$即可得到结论。

#### 单个公式换行

单个公式很长的时候需要换行，但仅允许生成一个编号时，可以用`split`标签包围公式代码，在需要转行的地方使用`\\`，每行需要使用1个`&`来标识对齐的位置，结束后可使用`\tag{...}`标签编号。

在用`equation`的时候内部可以用`aligned`来将单个公式换行

```latex
$$
\begin{split}
a &= b \\
c &= d \\
e &= f
\end{split}\tag{1.3}
$$
```

> eg.

$$
\begin{split} a &= b \ c &= d \ e &= f \end{split}\tag{1.3}
$$

{% hint style="warning" %}
注意：每行只允许出现一个`&`，使用`split`标签后，编号会**上下居中**显示。
{% endhint %}

```latex
\begin{equation}
  \begin{aligned}
    \mathrm{E}_{B}\left[\mathcal{L}\left(w_{B}^{n_{p}}\right)-\mathcal{L}\left(w^{*}\right)\right] \leq \frac{\alpha^{2} L M}{2 \gamma c} \frac{(B-1)}{B_{d}}+\left(1-\frac{(B-1)}{B_{d}}\right) \frac{L D^{2}}{2} \\
    +\frac{1}{B_{d}} \sum_{l=1}^{B-1}(1-\gamma c)^{l n_{p}}\left[\frac{L D^{2}}{2}-\frac{\alpha^{2} L M}{2 \gamma c}\right]  
  \end{aligned}
\end{equation}
```

$$
\begin{equation} \begin{aligned} \mathrm{E}*{B}\left\[\mathcal{L}\left(w*{B}^{n\_{p}}\right)-\mathcal{L}\left(w^{\*}\right)\right] \leq \frac{\alpha^{2} L M}{2 \gamma c} \frac{(B-1)}{B\_{d}}+\left(1-\frac{(B-1)}{B\_{d}}\right) \frac{L D^{2}}{2} \ +\frac{1}{B\_{d}} \sum\_{l=1}^{B-1}(1-\gamma c)^{l n\_{p}}\left\[\frac{L D^{2}}{2}-\frac{\alpha^{2} L M}{2 \gamma c}\right] \end{aligned} \end{equation}
$$

#### 多行的独立公式

有时候需要罗列多个公式，可以用`eqnarray*`标签包围公式代码，在需要转行的地方使用`\\`，每行需要使用2个`&`来标识对齐位置，两个`&...&`号之间的是公式间对齐的位置，每行公式后可使用`\tag{...}`标签编号：

```latex
$$
\begin{eqnarray*}
x^n+y^n &=& z^n \tag{1.4} \\
x+y &=& z \tag{1.5}
\end{eqnarray*}
$$
```

$$
\begin{eqnarray\*} x^n+y^n &=& z^n \tag{1.4} \ x+y &=& z \tag{1.5} \end{eqnarray\*}
$$

以上就是常见的Markdown工具环境下的*LaTeX*公式排版最简单的、最常用的代码命令。

{% hint style="success" %}
LaTex 数学公式完。
{% endhint %}

## Latex中的空格

$$
\verb|a,b| a,b \ \verb|$a,b$| $a,b$ \ \verb|a\thinspace b| a\thinspace b \ \verb|$a\thinspace b$| $a\thinspace b$ \ \verb|$a!b$| $a!b$ \ \verb|$a>b$| $a>b$ \ \verb|$a;b$| $a;b$ \ \verb|$a:b$| $a:b$ \ \verb|a\enspace b| a\enspace b \ \verb|$a\enspace b$| $a\enspace b$ \ \verb|a\quad b| a\quad b \ \verb|$a\quad b$| $a\quad b$ \ \verb|a\qquad b| a\qquad b \ \verb|$a\qquad b$| $a\qquad b$ \ \verb|a\hskip 1em b| a\hskip 1em b \ \verb|$a\hskip 1em b$| $a\hskip 1em b$ \ \verb|a\kern 1pc b| a\kern 1pc b \ \verb|$a\kern 1pc b$| $a\kern 1pc b$ \ \verb|a\hspace{35pt}b| a\hspace{35pt}b \ \verb|$a\hspace{35pt}b$| $a\hspace{35pt}b$ \ \verb|axyzb| axyzb \ \verb|a\hphantom{xyz}b| a\hphantom{xyz}b \ \verb|$axyzb$| $axyzb$ \ \verb|$a\hphantom{xyz}b$| $a\hphantom{xyz}b$ \ \verb|a{ }b| a{ }b \ \verb|$a{ }b$| $a{ }b$ \ \verb|a\space b| a\space b \ \verb|$a\space b$| $a\space b$ \ \verb|a\ b| a\ b \ \verb|$a\ b$| $a\ b$ \ \verb|a~~b| a~~b \ \verb|$a~~b$| $a~~b$ \\
$$

## Beamer slide

* 主题选择
* `\begin{frame}` 一张slide

  ```latex
  \begin{frame}[t]
    \frametitle{章节标题}
  \end{frame}
  ```
* `\section` `\subsection` 标题 子标题

  ```
  \section[章缩写标题]{主标题}\label{sec:1}
  \subsection[节缩写标题]{节主标题}\label{subsec:1-1}
  ```
* etc
* **UCAS-Beamer**
* 字体大小

```latex
\tiny x
\scriptsize x
\footnotesize x
\small x
\normalsize x
\large x
\Large x
\LARGE x
\huge x
\Huge x
```

* 分栏

```latex
\begin{columns}
  \begin{column}{0.55\textwidth}
    ColumnContent1
  \end{column}
  \begin{column}{0.45\textwidth}
    ColumnContent2
  \end{column}
\end{columns}
```

## Reference

\[1] [Markdown下LaTeX公式、编号、对齐](https://www.zybuluo.com/fyywy520/note/82980)

\[2] [latex:公式的序号](https://www.cnblogs.com/suerchen/p/4817711.html)

\[3] [UCAS-Beamer](https://github.com/icgw/ucas-beamer/)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.junyangz.com/note/latex-note.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
