> 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/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{Exploring math display styles}
\author{Overleaf team}
\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://ayakaleaf-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.
