> For the complete documentation index, see [llms.txt](https://ayakaleaf-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://ayakaleaf-pro.ayaka.space/latex/zh-cn/shen-du-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                                                                                                     | 此函数排版其参数时不占用任何水平空间，并在两侧对称地伸出。如上所示，此函数可用于去除下标、指数等中可能出现的一些多余空白。                                     |
| mathrlap\nmathllap                                                                                           | 与 mathclap 相同，但分别只向右侧或左侧伸出。                                                                       |
| cramped                                                                                                      | 类似于 mathclap，这会使某些项目更紧凑。例如，它会让指数之间更紧一些，这在有不止一层指数时尤其有用。                                            |
| crampedclap\ncrampedrlap\ncrampedllap                                                                        | 同时应用 cramped 和 mathclap（或 mathrlap 等）。效果与分别应用相同，但处理性能更好。                                          |
| smashoperator                                                                                                | 将文本压缩得像上面所有函数的组合。大多数情况下更易使用，但你会失去一些控制，也可能对结果不太满意。在这种情况下，请分别使用上面的函数。                               |
| adjustlimits                                                                                                 | 作用于极限（\lim），使更复杂的极限在垂直方向对齐。                                                                       |
| SwapAboveDisplaySkip                                                                                         | 消除公式上方的一些空白。                                                                                      |
| newtagform\nrenewtagform\nusetagform                                                                         | “标签”就是公式编号，这组函数允许你修改它们，例如更改括号、样式等。                                                                |
| refeq                                                                                                        | 一种在文档正文中引用函数的替代方式，不会造成字体不匹配问题。                                                                    |
| showonlyrefs                                                                                                 | 这是一个标志，而不是函数，但仍然很有用。如果设置，它只会为正文中被引用的公式分配编号。                                                       |
| showmanualtags                                                                                               | 与 showonlyrefs 相同，但适用于已设置手动标签的公式。                                                                 |
| noeqref                                                                                                      | 允许你为上述两个标志创建例外，以显示公式编号或标签，即使它在正文中没有被引用。                                                           |
| xleftrightarrow\nxLeftarrow\nxRightarrow\nxhookleftarrow\nxhookrightarrow\nxmapsto                           | 用于绘制各种箭头的一组函数，这些箭头会根据需要扩展以容纳相关文本。                                                                 |
| xrightharpoondown\nxleftharpoondown\nxrightharpoonup\nxleftharpoonup\nxrightleftharpoons\nxleftrightharpoons | 一组“鱼叉”或竖直箭头。与箭头类似，它们会按需要扩展                                                                        |
| overbrace\nunderbrace                                                                                        | 在公式上方或下方加上大括号。与 LaTeX 内置的函数相同，但通常排版效果更好。如果需要原始的 LaTeX 函数，可以使用 \LaTeXoverbrace 和 \LaTeXunderbrace。 |
| overbracket\nunderbracket                                                                                    | 像 overbrace 和 underbrace 一样放在公式上方或下方，但使用方括号。                                                      |
| begin{matrix} and friends                                                                                    | 矩阵排版有若干选项。它们主要用于比默认设置更好地居中元素，但也有一些其他选项，如 smallmatrix。我建议你在定义好矩阵后查看官方 mathtools 文档，以确定哪一个最适合你的需求。  |
| multlined                                                                                                    | 将一个长公式拆分为多个部分，类似于上面第一个示例中的分裂分式。                                                                   |
| begin{cases} and friends                                                                                     | 用于正确排版分段函数公式的工具。同样可用的选项很多，与其一一列举，不如在你了解分段函数公式的样子后参考 mathtools 官方文档。                               |
| MoveEqLeft                                                                                                   | 如有必要，可用于给公式产生缩进。                                                                                  |
| Aboxed                                                                                                       | 为公式加上边框。                                                                                          |
| ArrowBetweenLines\nvdotswithin\nshortvdotswithin\nMTFlushSpaceAbove\nMTFlushSpaceBelow                       | 这些函数可用于在公式、箭头、点等之间的空白处绘制内容。                                                                       |
| shortintertext                                                                                               | 类似 amsmath 中的 \intertext 函数，它允许在一系列公式中插入少量文字，而不会破坏对齐。这个版本的函数产生的空白更少。                              |
| DeclarePairedDelimiter                                                                                       | 允许定义新的定界符；文档中的一个示例是创建一组高度适合分式的绝对值竖线。这个函数还有一些高级选项可用。                                               |
| lparen\nrparen                                                                                               | 相当于 \left(、\right)。为兼容性而提供。                                                                       |
| vcentcolon                                                                                                   | 绘制一个垂直居中的冒号。                                                                                      |
| nuparrow\nndownarrow\nbigtimes                                                                               | 提供一些有时其他地方无法获得的字符。                                                                                |
| prescript                                                                                                    | 允许在字符前放置上标和下标，如上面的示例 3 所示。                                                                        |
| begin{spreadlines}                                                                                           | spreadlines 环境允许你显式定义公式之间的垂直间距。                                                                   |
| splitfrac\nsplitdfrac                                                                                        | 允许在分式中拆分分子或分母，如上面的示例 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://ayakaleaf-pro.ayaka.space/latex/zh-cn/shen-du-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.
