> 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-tw/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/b933f649e86f3e77c9b6a397aa4e2cd98a352c3f)

#### 較長的求和參數

如果沒有 `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/6e18e03f72740c11e3bb586444a69b66367afbff)

#### 左側上下標

可在符號左側（前方）加上上標與下標。以下是一個化學範例：

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

![U238.png](/files/5df43d4a9c08dbb5b216e4fe22be674b8ab4ef1f)

這些完整範例是開始探索的好地方 `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 文件，以判斷哪一種最符合你的需求。 |
| multlined                                                                                                                     | 將一個長方程式拆成多個部分，類似於上面第一個範例中的拆分分數。                                                                    |
| 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-tw/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.
