> 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/latex-ji-chu/02-paragraphs-and-new-lines.md).

# 段落和换行

## 引言

本文介绍 *基础* LaTeX 段落格式设置，包括如何更改文本对齐方式。更详细的信息和更多示例可在文章中找到 [文本对齐](/latex/zh-cn/ge-shi-hua/06-text-alignment.md) 和 [段落格式](/latex/zh-cn/ge-shi-hua/04-articles-how-to-change-paragraph-spacing-in-latex.md).

## 第一个示例

让我们从一个示例开始：通过将两个居中的段落写在一个 `center` 环境中来排版。请注意，通过在它们之间插入一个空行即可开始一个新段落——虽然这是一种常用方法，但并不是开始新段落的唯一方式。

```latex
\begin{center}
示例 1：下面的段落（引号中的内容）是
使用 center 环境实现居中对齐的示例。

``La\TeX{} 是一种文档排版系统和文档标记
语言。\LaTeX{} 使用 \TeX{} 排版程序来格式化
其输出，并且它本身是用 \TeX{} 宏语言编写的。
\LaTeX{} 不是某个特定的（可执行）排版程序的名称，而是
指一组命令（\TeX{} 宏），它们构成了标记
用于排版 \LaTeX{} 文档的约定。"
\end{center}
```

[在 Overleaf 中打开此示例](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Basic+paragraph+formatting\&snip=%5Cdocumentclass%7Barticle%7D%0A%25+Using+the+geometry+package+with+a+small%0A%25+page+size+to+create+the+article+graphic%0A%5Cusepackage%5Bpaperheight%3D6in%2C%0A+++paperwidth%3D5in%2C%0A+++top%3D10mm%2C%0A+++bottom%3D20mm%2C%0A+++left%3D10mm%2C%0A+++right%3D10mm%5D%7Bgeometry%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cbegin%7Bcenter%7D%0AExample+1%3A+The+following+paragraph+%28given+in+quotes%29+is+an+%0Aexample+of+centred+alignment+using+the+center+environment.+%0A%0A%60%60La%5CTeX%7B%7D+is+a+document+preparation+system+and+document+markup+%0Alanguage.+%5CLaTeX%7B%7D+uses+the+%5CTeX%7B%7D+typesetting+program+for+formatting+%0Aits+output%2C+and+is+itself+written+in+the+%5CTeX%7B%7D+macro+language.+%0A%5CLaTeX%7B%7D+is+not+the+name+of+a+particular+%28executable%29+typesetting+program%2C+but+%0Arefers+to+the+suite+of+commands+%28%5CTeX%7B%7D+macros%29+which+form+the+markup+%0Aconventions+used+to+typeset+%5CLaTeX%7B%7D+documents.%22%0A%5Cend%7Bcenter%7D%0A%5Cend%7Bdocument%7D)

此示例生成以下输出：

![LaTeX 居中段落示例](/files/02f16718dc8910a8e9ea920472464684b59098fa)

## 开始新段落

如上所述，开始新段落的一种方式是在其中插入一个空行，但下面的代码片段展示了另一种使用 `\par` 命令设置为特定值：

```latex
这是第一个段落中的文本。
这是第一个段落中的文本。
这是第一个段落中的文本。\par
这是第二个段落中的文本。
这是第二个段落中的文本。
这是第二个段落中的文本。
```

[在 Overleaf 中打开此示例](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Starting+a+new+paragraph\&snip=%5Cdocumentclass%7Barticle%7D%0A%25+Using+the+geometry+package+with+a+small%0A%25+page+size+to+create+the+article+graphic%0A%5Cusepackage%5Bpaperheight%3D6in%2C%0A+++paperwidth%3D5in%2C%0A+++top%3D10mm%2C%0A+++bottom%3D20mm%2C%0A+++left%3D10mm%2C%0A+++right%3D10mm%5D%7Bgeometry%7D%0A%5Cbegin%7Bdocument%7D%0AThis+is+text+contained+in+the+first+paragraph.+%0AThis+is+text+contained+in+the+first+paragraph.+%0AThis+is+text+contained+in+the+first+paragraph.%5Cpar%0AThis+is+text+contained+in+the+second+paragraph.+%0AThis+is+text+contained+in+the+second+paragraph.%0AThis+is+text+contained+in+the+second+paragraph.%0A%5Cend%7Bdocument%7D)

此示例生成以下输出：

![使用 \par 命令创建段落](/files/c1fe5977043d7448b60837995ad95fa11f6f285d)

## 段落对齐

默认情况下，LaTeX 中的段落是两端对齐的，即左右边距都对齐。如果你想排版一个 *非对齐的* 段落，可以使用 `flushleft` 或 `flushright` 这些环境。

### flushleft 和 flushright 环境

下一个示例演示在 `flushleft` 和 `flushright` 环境中排版段落——关于 `center` 环境的示例，请参见章节 [第一个示例](#a-first-example).

```latex
\section*{左对齐排版的段落}

\begin{flushleft}
La\TeX{} 是一种文档排版系统和文档标记
语言。\LaTeX{} 使用 \TeX{} 排版程序来格式化
其输出，并且它本身是用 \TeX{} 宏语言编写的。
\LaTeX{} 不是某个特定的（可执行）排版程序的名称，而是
指一组命令（\TeX{} 宏），它们构成了标记
用于排版 \LaTeX{} 文档的约定。
\end{flushleft}

\section*{右对齐排版的段落}

\begin{flushright}
La\TeX{} 是一种文档排版系统和文档标记
语言。\LaTeX{} 使用 \TeX{} 排版程序来格式化
其输出，并且它本身是用 \TeX{} 宏语言编写的。
\LaTeX{} 不是某个特定的（可执行）排版程序的名称，而是
指一组命令（\TeX{} 宏），它们构成了标记
用于排版 \LaTeX{} 文档的约定。
\end{flushright}
```

[在 Overleaf 中打开此示例](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Example+of+flushleft+and+flushright\&snip=%5Cdocumentclass%7Barticle%7D%0A%25+Using+the+geometry+package+with+a+small%0A%25+page+size+to+create+the+article+graphic%0A%5Cusepackage%5Bpaperheight%3D6in%2C%0A+++paperwidth%3D5in%2C%0A+++top%3D10mm%2C%0A+++bottom%3D20mm%2C%0A+++left%3D10mm%2C%0A+++right%3D10mm%5D%7Bgeometry%7D%0A%5Cbegin%7Bdocument%7D%0A%5Csection%2A%7BA+paragraph+typeset+flush+left%7D%0A%0A%5Cbegin%7Bflushleft%7D%0ALa%5CTeX%7B%7D+is+a+document+preparation+system+and+document+markup+%0Alanguage.+%5CLaTeX%7B%7D+uses+the+%5CTeX%7B%7D+typesetting+program+for+formatting+%0Aits+output%2C+and+is+itself+written+in+the+%5CTeX%7B%7D+macro+language.+%0A%5CLaTeX%7B%7D+is+not+the+name+of+a+particular+%28executable%29+typesetting+program%2C+but+%0Arefers+to+the+suite+of+commands+%28%5CTeX%7B%7D+macros%29+which+form+the+markup+%0Aconventions+used+to+typeset+%5CLaTeX%7B%7D+documents.%0A%5Cend%7Bflushleft%7D%0A%0A%5Csection%2A%7BA+paragraph+typeset+flush+right%7D%0A%0A%5Cbegin%7Bflushright%7D%0ALa%5CTeX%7B%7D+is+a+document+preparation+system+and+document+markup+%0Alanguage.+%5CLaTeX%7B%7D+uses+the+%5CTeX%7B%7D+typesetting+program+for+formatting+%0Aits+output%2C+and+is+itself+written+in+the+%5CTeX%7B%7D+macro+language.+%0A%5CLaTeX%7B%7D+is+not+the+name+of+a+particular+%28executable%29+typesetting+program%2C+but+%0Arefers+to+the+suite+of+commands+%28%5CTeX%7B%7D+macros%29+which+form+the+markup+%0Aconventions+used+to+typeset+%5CLaTeX%7B%7D+documents.%0A%5Cend%7Bflushright%7D%0A%5Cend%7Bdocument%7D)

此示例生成以下输出：

![LaTeX 的 flushleft 和 flushright 环境](/files/6686bbba1389ab06b4896765fb2c43bbda72f4ea)

### \raggedright 和 \raggedleft

除了使用诸如 `flushleft`, `flushright` 或 `center` 之外，还有所谓的“切换”命令：

* `\raggedright`，它是对使用 `flushleft` 环境
* `\raggedleft`，它是对使用 `flushright` 环境
* `\centering`，它是对使用 `center` 环境

这些切换命令会从插入的位置开始改变文本对齐方式，一直到文档末尾——除非其作用被限制在一个组中，或被另一个切换命令改变。

在下面的示例中， `\raggedright`, `\raggedleft` 和 `\centering` 的作用被局部化，因为它们是在由 `\begingroup ... \endgroup`创建的组内使用的。此外，请注意，在每种情况下，段落文本后面都有一个空行，然后才是 `\endgroup` 命令，它会触发 LaTeX 排版该段落，同时由 `\raggedright`, `\raggedleft` 和 `\centering` 应用的设置仍然有效。

```latex
\section*{完全两端对齐的段落}
\LaTeX{} 不是某个特定的（可执行）排版程序的名称，而是指一组命令（\TeX{} 宏），它们构成了标记
用于排版 \LaTeX{} 文档的约定。

\section*{使用 \texttt{\string\raggedright} 排版的段落}

\begingroup
\raggedright
\LaTeX{} 不是某个特定的（可执行）排版程序的名称，而是指一组命令（\TeX{} 宏），它们构成了标记
用于排版 \LaTeX{} 文档的约定。

\endgroup

\section*{使用 \texttt{\string\raggedleft} 排版的段落}

\begingroup
\raggedleft
\LaTeX{} 不是某个特定的（可执行）排版程序的名称，而是指一组命令（\TeX{} 宏），它们构成了标记
用于排版 \LaTeX{} 文档的约定。

\endgroup

\section*{使用 \texttt{\string\centering} 排版的段落}

\begingroup
\centering
\LaTeX{} 不是某个特定的（可执行）排版程序的名称，而是指一组命令（\TeX{} 宏），它们构成了标记
用于排版 \LaTeX{} 文档的约定。

\endgroup
```

[在 Overleaf 中打开此示例](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Non-justified+paragraph+formatting+options\&snip=%5Cdocumentclass%7Barticle%7D%0A%25+Using+the+geometry+package+with+a+small%0A%25+page+size+to+create+the+article+graphic%0A%5Cusepackage%5Bpaperheight%3D6in%2C%0A+++paperwidth%3D5in%2C%0A+++top%3D10mm%2C%0A+++bottom%3D20mm%2C%0A+++left%3D10mm%2C%0A+++right%3D10mm%5D%7Bgeometry%7D%0A%5Cbegin%7Bdocument%7D%0A%5Csection%2A%7BA+fully+justified++typeset+paragraph%7D+%0A%5CLaTeX%7B%7D+is+not+the+name+of+a+particular+%28executable%29+typesetting+program%2C+but+refers+to+the+suite+of+commands+%28%5CTeX%7B%7D+macros%29+which+form+the+markup+%0Aconventions+used+to+typeset+%5CLaTeX%7B%7D+documents.%0A%0A%5Csection%2A%7BA+paragraph+typeset+using+%5Ctexttt%7B%5Cstring%5Craggedright%7D%7D%0A%0A%5Cbegingroup%0A%5Craggedright+%0A%5CLaTeX%7B%7D+is+not+the+name+of+a+particular+%28executable%29+typesetting+program%2C+but+refers+to+the+suite+of+commands+%28%5CTeX%7B%7D+macros%29+which+form+the+markup+%0Aconventions+used+to+typeset+%5CLaTeX%7B%7D+documents.%0A%0A%5Cendgroup%0A%0A%5Csection%2A%7BA+paragraph+typeset+using+%5Ctexttt%7B%5Cstring%5Craggedleft%7D%7D%0A%0A%5Cbegingroup%0A%5Craggedleft+%0A%5CLaTeX%7B%7D+is+not+the+name+of+a+particular+%28executable%29+typesetting+program%2C+but+refers+to+the+suite+of+commands+%28%5CTeX%7B%7D+macros%29+which+form+the+markup+%0Aconventions+used+to+typeset+%5CLaTeX%7B%7D+documents.%0A%0A%5Cendgroup%0A%0A%5Csection%2A%7BA+paragraph+typeset+using+%5Ctexttt%7B%5Cstring%5Ccentering%7D%7D%0A%0A%5Cbegingroup%0A%5Ccentering+%0A%5CLaTeX%7B%7D+is+not+the+name+of+a+particular+%28executable%29+typesetting+program%2C+but+refers+to+the+suite+of+commands+%28%5CTeX%7B%7D+macros%29+which+form+the+markup+%0Aconventions+used+to+typeset+%5CLaTeX%7B%7D+documents.%0A%0A%5Cendgroup%0A%5Cend%7Bdocument%7D)

此示例生成以下输出：

![用于排版 LaTeX 段落的各种对齐选项](/files/ac5cf71c64fa2f36676871c2be84b059b21278da)

有关文本对齐的更详细信息和示例，请参见 [Overleaf 关于文本对齐的文章](/latex/zh-cn/ge-shi-hua/06-text-alignment.md) 其中还讨论了使用 [ragged2e LaTeX 宏包](https://ctan.org/pkg/ragged2e?lang=en) 来排版参差对齐文本并配置断字。

## 段落缩进

默认情况下，新段落通常会缩进一定量，该缩进由一个名为 `\parindent` 的参数控制，其值可以使用命令 `\setlength`；例如：

```latex
\setlength{\parindent}{20pt}
```

将 `\parindent` 设为 20pt。你可以通过将 `\parindent` 设为 0pt（或 0mm、0cm 等），或者使用命令 `\noindent` 放在段落开头来避免缩进。默认情况下，LaTeX 不会缩进文档某一节中的首段，如下例所示：

```latex
\setlength{\parindent}{20pt}

\section*{这是一个章节}
\textbf{第一段}是某个章节中的内容，如你所见，它没有缩进。段落中还有更多文本。段落中还有更多文本。

\textbf{第二段}。如你所见，它有缩进。段落中还有更多文本。段落中还有更多文本。

\noindent\textbf{第三段}。由于使用了 \texttt{\string\noindent}，这一段也没有缩进。段落中还有更多文本。段落中还有更多文本。当前 \verb|\parindent| 的值是 \the\parindent。段落中还有更多文本。
```

[在 Overleaf 中打开此示例](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Basic+paragraph+indentation\&snip=%5Cdocumentclass%7Barticle%7D%0A%25+Using+the+geometry+package+with+a+small%0A%25+page+size+to+create+the+article+graphic%0A%5Cusepackage%5Bpaperheight%3D6in%2C%0A+++paperwidth%3D5in%2C%0A+++top%3D10mm%2C%0A+++bottom%3D20mm%2C%0A+++left%3D10mm%2C%0A+++right%3D10mm%5D%7Bgeometry%7D%0A%5Cbegin%7Bdocument%7D%0A%5Csetlength%7B%5Cparindent%7D%7B20pt%7D%0A%0A%5Csection%2A%7BThis+is+a+section%7D%0A%5Ctextbf%7BFirst+paragraph%7D+of+a+section+which%2C+as+you+can+see%2C+is+not+indented.+This+is+more+text+in+the+paragraph.+This+is+more+text+in+the+paragraph.%0A%0A%5Ctextbf%7BSecond+paragraph%7D.+As+you+can+see+it+is+indented.+This+is+more+text+in+the+paragraph.+This+is+more+text+in+the+paragraph.+%0A%0A%5Cnoindent%5Ctextbf%7BThird+paragraph%7D.+This+too+is+not+indented+due+to+use+of+%5Ctexttt%7B%5Cstring%5Cnoindent%7D.+This+is+more+text+in+the+paragraph.+This+is+more+text+in+the+paragraph.++The+current+value+of+%5Cverb%7C%5Cparindent%7C+is+%5Cthe%5Cparindent.+This+is+more+text+in+the+paragraph.%0A%5Cend%7Bdocument%7D)

此示例生成以下输出：

![演示 LaTeX 段落缩进](/files/5143c30f16bbd82385aa1592e9ccf25964cbdfcc)

### 关于缩进相关命令的说明

段落缩进受三个命令控制或影响：

* `\parindent`：一个存储当前段落缩进大小的参数
* `\indent`：该命令的效果取决于其使用位置：
  * 在水平模式下（在段落中或在一个 `\hbox`）或数学模式下，它会插入一个宽度为 `\parindent`
  * 在垂直模式下（在段落之间或在一个 `\vbox`）它会触发开始一个新的缩进段落
* `\noindent`：该命令的效果也取决于其使用位置：
  * 在垂直模式下（在段落之间或在一个 `\vbox`）它也会触发一个新的 *非缩进的* 段落
  * 在水平模式下（在段落中或在一个 `\hbox`）或数学模式下它没有效果：会被忽略

下面的示例演示 `\indent`:

```latex
\documentclass{article}
% 使用 geometry 宏包并设置较小的
% 页面尺寸以生成文章图示
\usepackage[paperheight=6in,
   paperwidth=5in,
   top=10mm,
   bottom=20mm,
   left=10mm,
   right=10mm]{geometry}
\begin{document}
\noindent 一个包含一些文本的新段落，然后是一个 \verb|\indent|\indent 命令。接下来是一些行内数学公式，它也有缩进 $y\indent x$。\verb|\indent| 在 \verb|\hbox| 中使用时也有效，例如 \verb|\hbox{A\indent B}|，其产生 \hbox{A\indent B}。
\end{document}
```

[在 Overleaf 中打开此示例](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Example+of+the+%5Cindent+command\&snip=%5Cdocumentclass%7Barticle%7D%0A%25+Using+the+geometry+package+with+a+small%0A%25+page+size+to+create+the+article+graphic%0A%5Cusepackage%5Bpaperheight%3D6in%2C%0A+++paperwidth%3D5in%2C%0A+++top%3D10mm%2C%0A+++bottom%3D20mm%2C%0A+++left%3D10mm%2C%0A+++right%3D10mm%5D%7Bgeometry%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cnoindent+A+new+paragraph+with+some+text%2C+then+an+%5Cverb%7C%5Cindent%7C%5Cindent+command.+Next%2C+some+inline+math+which+also+has+an+indent+%24y%5Cindent+x%24.+%5Cverb%7C%5Cindent%7C+also+works+when+used+in+an+%5Cverb%7C%5Chbox%7C+such+as+%5Cverb%7C%5Chbox%7BA%5Cindent+B%7D%7C+which+produces+%5Chbox%7BA%5Cindent+B%7D.%0A%5Cend%7Bdocument%7D)

此示例生成以下输出：

![演示 \indent 命令](/files/f6f8a5a893c1ec2e9f518eb347872ec20c02d65e)

## 延伸阅读

更多信息请查看

* [段落格式](/latex/zh-cn/ge-shi-hua/04-articles-how-to-change-paragraph-spacing-in-latex.md)
* [文本对齐](/latex/zh-cn/ge-shi-hua/06-text-alignment.md)
* [LaTeX 中的长度](/latex/zh-cn/ge-shi-hua/01-lengths-in-latex.md)
* [换行与空白](/latex/zh-cn/ge-shi-hua/05-line-breaks-and-blank-spaces.md)
* [列表](/latex/zh-cn/latex-ji-chu/04-lists.md)
* [加粗、斜体和下划线](/latex/zh-cn/latex-ji-chu/03-bold-italics-and-underlining.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/latex-ji-chu/02-paragraphs-and-new-lines.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.
