> 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/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-tw/shu-xue/01-mathematical-expressions.md)
* [下標與上標](/latex/zh-tw/shu-xue/02-subscripts-and-superscripts.md)
* [使用 amsmath 對齊方程式](/latex/zh-tw/shu-xue/06-aligning-equations-with-amsmath.md)
* [數學模式中的間距](/latex/zh-tw/shu-xue/08-spacing-in-math-mode.md)
* [積分、加總與極限](/latex/zh-tw/shu-xue/09-integrals-sums-and-limits.md)
* [數學字型](/latex/zh-tw/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-tw/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.
