> For the complete documentation index, see [llms.txt](https://overleaf-pro.ayaka.space/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://overleaf-pro.ayaka.space/latex/zh-cn/shen-ru-wen-zhang/33-mathtools-for-beautiful-math.md).

# Mathtools——用于美观数学排版

**作者：Robert Murrish（2012年6月）**

`mathtools` 是你可能从未意识到自己需要的宏包。LaTeX 让公式排版变得很容易，而且 `mathtools` 让这些公式更加美观。

`mathtools` 是……的扩展 `amsmath`。如果你包含 `mathtools`，你就可以使用该宏包中的任何函数或宏。 `amsmath` 是一套用于公式排版的广泛工具，并且被广泛使用。 `mathtools` 扩展了 `amsmath` 函数，提供更多格式选项，并修正数学排版中一些更常见的问题。

### 几个例子

#### 双行分数

一个复杂的分数可能会延伸得过宽，以至于超过栏宽。将分子和/或分母拆成多行，是一种优雅的方式来让它保持在一起。

```latex
z=\frac{ab+cd+ef+gh+ij+kl+mn+op+qr}{y}
z=\frac{\splitfrac{ab+cd+ef+gh+ij}{+kl+mn+op+qr}}{y}
```

![Fract.png](/files/4d4adbd08bd54d8f30a7dc0c2516c907ab1c4ec0)

#### 长求和参数

如果没有 `mathtools` 函数 `\mathclap`，由于下方的索引，求和符号两侧会产生额外空白。一个简单的 `mathtools` 命令就能压缩结果。

```latex
P_e_i_\Delta = \sum_{j=1, j\not=k,i}E_iE_jB_i_j cos\delta_i_j\delta_i_j_\Delta + V_kE_iB_i_k cos\delta_i_k_o \delta_i_k_\Delta

P_e_i_\Delta = \sum_{\mathclap{j=1, j\not=k,i}}E_iE_jB_i_j cos\delta_i_j \delta_i_j_\Delta + V_kE_iB_i_k cos\delta_i_k_o \delta_i_k_\Delta
```

![Mathclap.png](/files/0f256fa9ca79108d1362fb7070c9d6aede50f87c)

#### 前置上下标

允许在符号左侧（前面）添加上标和下标。以下是一个化学示例：

```latex
\prescript{238}{92}{\mathbf{U}}
```

![U238.png](/files/4cbd16f0508825cad6b0cc8010144e761408eeb9)

这些完整示例是开始探索的好起点 `mathtools`，但这个宏包中还有许多其他工具可用。下面列出了该宏包包含的所有宏（截至本文撰写日期）。如需最新列表以及关于如何使用每一个宏的具体细节，请参阅 [其文档 `mathtools` 宏包](https://ctan.org/pkg/mathtools?lang=en).

|                                                                                                                               |                                                                                                   |
| ----------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- |
| **函数名**                                                                                                                       | **说明**                                                                                            |
| mathclap                                                                                                                      | 此函数在排版其参数时不占用任何水平空间，而是对称地向两侧伸出。如上所示，此函数可用于去除下标、上标等中可能出现的一些多余空白。                                   |
| <p>mathrlap<br>mathllap</p>                                                                                                   | 与 mathclap 相同，但分别只向右侧或左侧延伸。                                                                       |
| 压缩                                                                                                                            | 类似于 mathclap，此函数会压缩某些项目。例如，它会让上标更紧凑一些，这在有多层上标时尤其有用。                                               |
| <p>crampedclap<br>crampedrlap<br>crampedllap</p>                                                                              | 同时应用 cramped 和 mathclap（或 mathrlap 等）。效果与分别应用两者相同，但处理性能更高。                                        |
| smashoperator                                                                                                                 | 其压缩文本的效果类似于以上所有函数的组合。大多数情况下它更容易使用，但你会失去一些控制，结果可能也不太满意。在这种情况下，请分别使用上面的各个函数。                        |
| adjustlimits                                                                                                                  | 作用于极限（\lim），使更复杂的极限在垂直方向上对齐。                                                                      |
| SwapAboveDisplaySkip                                                                                                          | 消除公式上方的一些空白。                                                                                      |
| <p>newtagform<br>renewtagform<br>usetagform</p>                                                                               | “标签”就是公式编号，而这组函数允许你修改它们，例如更改括号、样式等。                                                               |
| refeq                                                                                                                         | 在文档正文中引用函数的另一种方式，而不会导致字体不匹配问题。                                                                    |
| showonlyrefs                                                                                                                  | 这是一个标志，而不是函数，但仍然很有用。如果启用，只有在正文中被引用的公式才会获得公式编号。                                                    |
| showmanualtags                                                                                                                | 与 showonlyrefs 相同，但适用于已设置手动标签的公式。                                                                 |
| noeqref                                                                                                                       | 允许你为上面两个标志创建例外，即使某个公式未在正文中被引用，也可以显示其编号或标签。                                                        |
| <p>xleftrightarrow<br>xLeftarrow<br>xRightarrow<br>xhookleftarrow<br>xhookrightarrow<br>xmapsto</p>                           | 一组用于绘制各种箭头的函数，它们会根据需要扩展以适配相关文本。                                                                   |
| <p>xrightharpoondown<br>xleftharpoondown<br>xrightharpoonup<br>xleftharpoonup<br>xrightleftharpoons<br>xleftrightharpoons</p> | 一组“鱼叉箭头”或竖直箭头。与普通箭头类似，它们会根据需要扩展                                                                   |
| <p>overbrace<br>underbrace</p>                                                                                                | 在公式上方或下方加上大括号。与 LaTeX 内置函数相同，但通常排版效果更好。如果你需要原始的 LaTeX 函数，可以使用 \LaTeXoverbrace 和 \LaTeXunderbrace。 |
| <p>overbracket<br>underbracket</p>                                                                                            | 像 overbrace 和 underbrace 一样位于公式上方或下方，但使用方括号。                                                      |
| begin{matrix} 及其相关环境                                                                                                          | 矩阵排版有多种选项。它们主要比默认设置更能将元素居中，但也有其他选项，比如 smallmatrix。一旦你定义了矩阵，我建议你查看 mathtools 的官方文档，以确定哪种最适合你的需求。   |
| 多行对齐                                                                                                                          | 将长公式拆分成多个部分，类似于上面第一个示例中的分裂分数。                                                                     |
| begin{cases} 及其相关环境                                                                                                           | 用于正确排版分段函数公式的工具。同样，可用选项很多，这里不一一介绍；当你知道自己的分段公式长什么样后，请查阅 mathtools 的官方文档。                           |
| MoveEqLeft                                                                                                                    | 在必要时为公式生成缩进的一种方法。                                                                                 |
| Aboxed                                                                                                                        | 在公式周围画一个框。                                                                                        |
| <p>ArrowBetweenLines<br>vdotswithin<br>shortvdotswithin<br>MTFlushSpaceAbove<br>MTFlushSpaceBelow</p>                         | 这些函数可在公式、箭头、点等之间的空白处进行绘制。                                                                         |
| shortintertext                                                                                                                | 与 amsmath 中的 \intertext 函数类似，它允许在一系列公式中插入少量文本而不破坏对齐。此版本函数产生的空白更少。                                 |
| DeclarePairedDelimiter                                                                                                        | 允许定义新的定界符，文档中的一个例子是创建一组高度适合分数的绝对值竖线。此函数还提供一些高级选项。                                                 |
| <p>lparen<br>rparen</p>                                                                                                       | 等同于 \left(、\right)。为兼容性而提供。                                                                       |
| vcentcolon                                                                                                                    | 绘制一个垂直居中的冒号。                                                                                      |
| <p>nuparrow<br>ndownarrow<br>bigtimes</p>                                                                                     | 提供一些有时无法通过其他方式获得的字符。                                                                              |
| prescript                                                                                                                     | 允许在字符前添加上标和下标，如上面的示例 3 所示。                                                                        |
| begin{spreadlines}                                                                                                            | spreadlines 环境允许你显式定义公式之间的垂直间距。                                                                   |
| <p>splitfrac<br>splitdfrac</p>                                                                                                | 允许分数的分子或分母拆分为多行，如上面的示例 1 所示。                                                                      |

以下是一些可用的 mathtools 文档的直接链接：

* [`mathtools` CTAN 上的宏包及文档](https://ctan.org/pkg/mathtools?lang=en);
* [TUGboat 上的文章](http://www.tug.org/TUGboat/Articles/tb22-4/tb72perlS.pdf).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://overleaf-pro.ayaka.space/latex/zh-cn/shen-ru-wen-zhang/33-mathtools-for-beautiful-math.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
