> 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/10-display-style-in-math-mode.md).

# 数学模式中的显示样式

## 引言

本文将介绍如何手动调整排版数学的样式——不过我们先快速回顾一下行内样式和显示样式数学在视觉上的区别。

与段落文本一起以内联（嵌入）方式排版的数学，需要比将同一数学放在段落文本之外、作为独立的显示样式内容排版时占用更少的空间。为了实际看看这一点，我们来说明方程 $$f(x) = \sum\_{i=0}^{n} \frac{a\_i}{1+x}$$ 可能发散或收敛，这取决于 $$x$$. 我们也可以将 $$f(x)$$ 在段落之外以显示样式排版：

$$f(x) = \sum\_{i=0}^{n} \frac{a\_i}{1+x}$$

即使粗略看一眼前面的例子，也能发现数学符号的大小和格式发生了变化，例如 $$\sum$$ 以及其上下限的位置，还有上标、下标和分数在大小/位置上的变化。

这些数学排版问题是 TeX 引擎内置的排版算法与数学字体中某些间距参数相互作用的结果。这些字体参数有助于根据所用数学字体的设计特征，对数学排版进行微调。

## 覆盖默认的数学样式

有时你可能希望更改用于排版某段数学内容的默认样式。例如，你可能想把行内数学，如 $$f(x) = \frac{1}{1+x}$$，并将其放入段落中，但以显示样式排版： $$\displaystyle f(x) = \frac{1}{1+x}$$，尽管它会对行距产生很大影响。

TeX 引擎提供了若干命令，可用于覆盖数学内容默认的排版样式：

* `\textstyle`：应用用于段落中数学排版的样式
* `\displaystyle`：应用用于单独成行数学排版的样式
* `\scriptstyle`：应用用于下标或上标的样式
* `\scriptscriptstyle`：应用用于二级下标或上标的样式

这个经典例子取自《TeXBook》第 142 页，不过我们把 `$$` 替换为 LaTeX 更偏好的 `\[` 和 `\]`:

```latex
\[
a_0+{1\over a_1+
      {1\over a_2+
        {1 \over a_3 +
           {1 \over a_4}}}}
\]
```

默认情况下，它被排版为：

$$a\_0+{1\over a\_1+{1\over a\_2 +{1 \over a\_3 + {1 \over a\_4}}}}$$

可以通过使用 `\displaystyle` 命令设置为特定值：

```latex
\[
a_0+{1\over\displaystyle a_1+
      {1\over\displaystyle a_2+
        {1 \over\displaystyle a_3 +
           {1 \over\displaystyle a_4}}}}
\]
```

得到

$$a\_0+{1\over\displaystyle a\_1+{1\over\displaystyle a\_2+{1 \over\displaystyle a\_3 +{1 \over\displaystyle a\_4}}}}$$

下面是另一个示例，用来展示 `\textstyle`, `\scriptstyle` 和 `\scriptscriptstyle`:

```latex
\[
\begin{align*}
f(x) = \sum_{i=0}^{n} \frac{a_i}{1+x} \\
\textstyle f(x) = \textstyle \sum_{i=0}^{n} \frac{a_i}{1+x} \\
\scriptstyle f(x) = \scriptstyle \sum_{i=0}^{n} \frac{a_i}{1+x} \\
\scriptscriptstyle f(x) = \scriptscriptstyle \sum_{i=0}^{n} \frac{a_i}{1+x}
\end{align*}
\]
```

其显示效果为 $$\begin{align\*} f(x) = \sum\_{i=0}^{n} \frac{a\_i}{1+x} \ \textstyle f(x) = \textstyle \sum\_{i=0}^{n} \frac{a\_i}{1+x} \ \scriptstyle f(x) = \scriptstyle \sum\_{i=0}^{n} \frac{a\_i}{1+x} \ \scriptscriptstyle f(x) = \scriptscriptstyle \sum\_{i=0}^{n} \frac{a\_i}{1+x} \end{align\*}$$

这是一个你可以在 Overleaf 中打开的示例：

```latex
\documentclass{article}
\usepackage{amsmath}
\title{探索数学显示样式}
\author{Overleaf 团队}
\begin{document}
\maketitle
根据 \(x\) 的值，方程 \( f(x) = \sum_{i=0}^{n} \frac{a_i}{1+x} \) 可能发散或收敛。

\[ f(x) = \sum_{i=0}^{n} \frac{a_i}{1+x} \]

\vspace{1cm}

行内数学元素可以使用不同的样式设置：\(f(x) = \displaystyle \frac{1}{1+x}\)。显示数学内容也是如此：

\begin{align*}
f(x) = \sum_{i=0}^{n} \frac{a_i}{1+x} \\
\textstyle f(x) = \sum_{i=0}^{n} \frac{a_i}{1+x} \\
\scriptstyle f(x) = \sum_{i=0}^{n} \frac{a_i}{1+x} \\
\scriptscriptstyle f(x) = \sum_{i=0}^{n} \frac{a_i}{1+x}
\end{align*}
\end{document}
```

[在 Overleaf 中打开此示例](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Exploring+math+display+styles\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%7Bamsmath%7D%0A%5Ctitle%7BExploring+math+display+styles%7D%0A%5Cauthor%7BOverleaf+team%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cmaketitle%0ADepending+on+the+value+of+%5C%28x%5C%29+the+equation+%5C%28+f%28x%29+%3D+%5Csum_%7Bi%3D0%7D%5E%7Bn%7D+%5Cfrac%7Ba_i%7D%7B1%2Bx%7D+%5C%29+may+diverge+or+converge.%0A%0A%5C%5B+f%28x%29+%3D+%5Csum_%7Bi%3D0%7D%5E%7Bn%7D+%5Cfrac%7Ba_i%7D%7B1%2Bx%7D+%5C%5D%0A%0A%5Cvspace%7B1cm%7D%0A%0AInline+maths+elements+can+be+set+with+a+different+style%3A+%5C%28f%28x%29+%3D+%5Cdisplaystyle+%5Cfrac%7B1%7D%7B1%2Bx%7D%5C%29.+The+same+is+true+for+display+math+material%3A%0A%0A%5Cbegin%7Balign%2A%7D%0Af%28x%29+%3D+%5Csum_%7Bi%3D0%7D%5E%7Bn%7D+%5Cfrac%7Ba_i%7D%7B1%2Bx%7D+%5C%5C%0A%5Ctextstyle+f%28x%29+%3D+%5Csum_%7Bi%3D0%7D%5E%7Bn%7D+%5Cfrac%7Ba_i%7D%7B1%2Bx%7D+%5C%5C%0A%5Cscriptstyle+f%28x%29+%3D+%5Csum_%7Bi%3D0%7D%5E%7Bn%7D+%5Cfrac%7Ba_i%7D%7B1%2Bx%7D+%5C%5C%0A%5Cscriptscriptstyle+f%28x%29+%3D+%5Csum_%7Bi%3D0%7D%5E%7Bn%7D+%5Cfrac%7Ba_i%7D%7B1%2Bx%7D%0A%5Cend%7Balign%2A%7D%0A%5Cend%7Bdocument%7D)

## 进一步阅读

更多信息请参见

* [数学表达式](/latex/zh-cn/shu-xue/01-mathematical-expressions.md)
* [下标和上标](/latex/zh-cn/shu-xue/02-subscripts-and-superscripts.md)
* [使用 amsmath 对齐方程](/latex/zh-cn/shu-xue/06-aligning-equations-with-amsmath.md)
* [数学模式中的间距](/latex/zh-cn/shu-xue/08-spacing-in-math-mode.md)
* [积分、求和与极限](/latex/zh-cn/shu-xue/09-integrals-sums-and-limits.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/10-display-style-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.
