> 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/shu-xue/08-spacing-in-math-mode.md).

# 数学模式中的间距

本文将解释如何在数学模式中插入不同宽度的空白。

## 引言

在某些情况下，调整（La）TeX 默认的数学模式间距会很有用；让我们看一个例子：

```latex
\documentclass{article}
\usepackage{amssymb}
\begin{document}
假设我们有以下集合
\[
S = \{ z \in \mathbb{C}\, |\, |z| < 1 \} \quad \textrm{and} \quad S_2=\partial{S}
\]
\end{document}
```

[在 Overleaf 中打开此示例](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Math+mode+spacing+example\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%7Bamssymb%7D%0A%5Cbegin%7Bdocument%7D%0AAssume+we+have+the+next+sets%0A%5C%5B%0AS+%3D+%5C%7B+z+%5Cin+%5Cmathbb%7BC%7D%5C%2C+%7C%5C%2C+%7Cz%7C+%3C+1+%5C%7D+%5Cquad+%5Ctextrm%7Band%7D+%5Cquad+S_2%3D%5Cpartial%7BS%7D%0A%5C%5D%0A%5Cend%7Bdocument%7D)

此示例生成以下输出：

![展示数学间距调整的示例](/files/8b764ae4c5d456bd3cb6f81ea0441abd87ea1385)

如你在这个例子中看到的，数学文本可以通过一些特殊命令显式设置间距。

## 空白

下面的示例包含使用各种命令插入的完整空白列表，并展示它们对排版数学公式的效果。

```latex
\documentclass{article}
\usepackage{amsmath}
\begin{document}
数学模式中的空白。

\begin{align*}
f(x) &= x^2\! +3x\! +2 \\
f(x) &= x^2+3x+2 \\
f(x) &= x^2\, +3x\, +2 \\
f(x) &= x^2\: +3x\: +2 \\
f(x) &= x^2\; +3x\; +2 \\
f(x) &= x^2\ +3x\ +2 \\
f(x) &= x^2\quad +3x\quad +2 \\
f(x) &= x^2\qquad +3x\qquad +2
\end{align*}
\end{document}
```

[在 Overleaf 中打开此示例](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Math+mode+spacing+example\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%7Bamsmath%7D%0A%5Cbegin%7Bdocument%7D%0ASpaces+in+mathematical+mode.%0A%0A%5Cbegin%7Balign%2A%7D%0Af%28x%29+%26%3D+x%5E2%5C%21+%2B3x%5C%21+%2B2+%5C%5C%0Af%28x%29+%26%3D+x%5E2%2B3x%2B2+%5C%5C%0Af%28x%29+%26%3D+x%5E2%5C%2C+%2B3x%5C%2C+%2B2+%5C%5C%0Af%28x%29+%26%3D+x%5E2%5C%3A+%2B3x%5C%3A+%2B2+%5C%5C%0Af%28x%29+%26%3D+x%5E2%5C%3B+%2B3x%5C%3B+%2B2+%5C%5C%0Af%28x%29+%26%3D+x%5E2%5C+%2B3x%5C+%2B2+%5C%5C%0Af%28x%29+%26%3D+x%5E2%5Cquad+%2B3x%5Cquad+%2B2+%5C%5C%0Af%28x%29+%26%3D+x%5E2%5Cqquad+%2B3x%5Cqquad+%2B2%0A%5Cend%7Balign%2A%7D%0A%5Cend%7Bdocument%7D)

此示例生成以下输出：

![数学模式中调整间距的更多示例](/files/d2426418ddffa66c3a52b45cdbf0195626ec8e85)

请查看 [参考指南](#reference-guide) 以了解这些命令的说明。

**注意**：要查看 `align*` 环境，请参见 [使用 amsmath 对齐方程](/latex/zh-cn/shu-xue/06-aligning-equations-with-amsmath.md)

## 运算符间距

数学模式中运算符和关系符号周围的间距由特定的留白宽度控制：

* `\thinmuskip` （默认等于 3 mu）
* `\medmuskip` （默认等于 4 mu）
* `\thickmuskip` （默认等于 5 mu）

```latex
\begin{align*}
3ax+4by=5cz\\
3ax<4by+5cz
\end{align*}
```

[在 Overleaf 中打开此示例](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Math+mode+operator+spacing+example\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%7Bamsmath%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cbegin%7Balign%2A%7D%0A3ax%2B4by%3D5cz%5C%5C%0A3ax%3C4by%2B5cz%0A%5Cend%7Balign%2A%7D%0A%5Cend%7Bdocument%7D)

此示例生成以下输出：

![LaTeX 中的运算符间距](/files/4adab6c75a4a85c33954d5d832a08dd6b12e0f6e)

对于关系运算符，例如 $$<$$, $$>$$ 和 $$=$$，LaTeX 会设置 `\thickmuskip` 间距。但对于二元运算符，例如 $$+$$, $$-$$ 和 $$\times$$， `\medmuskip` 也会设置间距。其差别几乎难以察觉。

## 用户自定义的二元和关系运算符

你可以强制二元或关系运算符使用的间距，因此你可以 [定义你自己的](/latex/zh-cn/ming-ling/01-commands.md).

```latex
\begin{align*}
34x^2a \mathbin{\#} 13bc \\
34x^2a \mathrel{\#} 13bc
\end{align*}
```

[在 Overleaf 中打开此示例](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Defining+your+own+math+operators\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%7Bamsmath%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cbegin%7Balign%2A%7D%0A34x%5E2a+%5Cmathbin%7B%5C%23%7D+13bc+%5C%5C%0A34x%5E2a+%5Cmathrel%7B%5C%23%7D+13bc%0A%5Cend%7Balign%2A%7D%0A%5Cend%7Bdocument%7D)

此示例生成以下输出：

![定义你自己的二元或关系运算符](/files/df2accde802c65f70c7c309493bb3fdc6af9e314)

前面的示例在前后设置了特定间距 `#` 通过使用 `\mathrel` （关系运算符）和 `\mathbin` （二元运算符）命令。

## 参考指南

**间距命令说明**

| LaTeX 代码        | 说明                                                                     |
| --------------- | ---------------------------------------------------------------------- |
| `\quad`         | 等于当前字体大小的空白（= 18 [mu](/latex/zh-cn/ge-shi-hua/01-lengths-in-latex.md)) |
| `\,`            | 当前字体大小的 3/18 `\quad` （= 3 mu）                                          |
| `\:`            | 当前字体大小的 4/18 `\quad` （= 4 mu）                                          |
| `\;`            | 当前字体大小的 5/18 `\quad` （= 5 mu）                                          |
| `\!`            | 当前字体大小的 -3/18 `\quad` （= -3 mu）                                        |
| `\` （反斜杠后面的空格！） | 相当于普通文本中的空格                                                            |
| `\qquad`        | 两倍于 `\quad` （= 36 mu）                                                  |

## 进一步阅读

更多信息请参见

* [数学表达式](/latex/zh-cn/shu-xue/01-mathematical-expressions.md)
* [括号](/latex/zh-cn/shu-xue/03-brackets-and-parentheses.md)
* [使用 amsmath 对齐方程](/latex/zh-cn/shu-xue/06-aligning-equations-with-amsmath.md)
* [数学模式中的显示样式](/latex/zh-cn/shu-xue/10-display-style-in-math-mode.md)
* [希腊字母和数学符号列表](/latex/zh-cn/shu-xue/11-list-of-greek-letters-and-math-symbols.md)
* [数学字体](/latex/zh-cn/shu-xue/12-mathematical-fonts.md)
* [LaTeX2ε 不那么简短的介绍](http://www.ctan.org/tex-archive/info/lshort/)


---

# 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/shu-xue/08-spacing-in-math-mode.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.
