> 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/ge-shi-hua/05-line-breaks-and-blank-spaces.md).

# 换行和空格

在 LaTeX 中打断文档流通常不建议，除非你是 [在创建宏](/latex/zh-cn/lei-wen-jian/03-writing-your-own-package.md)。不过，有时需要对文档版式有更多控制；因此本文将说明如何插入换行、分页和任意空白。

## 引言

最标准的换行方式是创建一个新段落。这可以通过在代码中留空一行来实现。

```latex
\documentclass{article}
\begin{document}
这一段不包含任何信息
其目的是提供一个如何开始新段落的示例。
正如你所见，
单行
在代码中的换行
在文本中表现为一个空格。

但是，留空一行会开始一个新段落。
\end{document}
```

[在 Overleaf 中打开此示例](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=New+paragraph\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cbegin%7Bdocument%7D%0AThis+paragraph+contains+no+information%0Aand+its+purpose+is+to+provide+an+example+on+how+to+start+a+new+paragraph.%0AAs+you+can+see%2C%0Asingle+line%0Abreak+in+the+code%0Aacts+as+a+space+in+text.%0A%0AHowever%2C+leaving+an+empty+line+starts+a+new+paragraph.%0A%5Cend%7Bdocument%7D)

![LineBreaksEx1aupdated.png](/files/78e8808fcf62b26a9a45ad062c7c27a860aaa323)

这并不是插入换行的唯一命令，在 [下一节](#line-breaks) 接下来还会介绍另外两个。

## 换行

如前所述，插入换行有不止一种方法。

```latex
\documentclass{article}
\usepackage[utf8]{inputenc}

\begin{document}
本文档中的某些内容。这一段不包含任何信息
其目的是提供一个如何插入空白
和换行的示例。\\
插入换行时，文本不会缩进，
还有几个额外的换行命令。 \newline
这一段完全没有信息。我们正在探讨
换行。 \hfill \break
并组合两个命令
\end{document}
```

[在 Overleaf 中打开此示例](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Another+line+break+example\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%5Butf8%5D%7Binputenc%7D%0A%0A%5Cbegin%7Bdocument%7D%0ASomething+in+this+document.+This+paragraph+contains+no+information+%0Aand+its+purposes+is+to+provide+an+example+on+how+to+insert+white+%0Aspaces+and+lines+breaks.%5C%5C%0AWhen+a+line+break+is+inserted%2C+the+text+is+not+indented%2C+there+%0Aare+a+couple+of+extra+commands+do+line+breaks.+%5Cnewline%0AThis+paragraph+provides+no+information+whatsoever.+We+are+exploring+%0Aline+breaks.+%5Chfill+%5Cbreak%0AAnd+combining+two+commands%0A%5Cend%7Bdocument%7D)

![LineBreaksEx2new.png](/files/f91ab49a2c2a6dd82490dc3cecdf2bb23eb8869f)

这里有三个命令在示例中的作用相同：

* `\\` （两个反斜杠）
* `\newline`
* `\hfill \break`

更多换行命令请参见 [参考指南](#reference-guide).

## 分页

有两个用于插入分页的命令， `clearpage` 和 `newpage`。以下是使用 `clearpage`.

```latex
\documentclass{article}
\usepackage[utf8]{inputenc}

\begin{document}
本文档中的某些内容。这一段不包含任何信息，并且
其目的是提供一个如何插入空白
和换行的示例。\\
插入换行时，文本不会缩进，还有
几个额外的换行命令。 \newline
这一段完全没有信息。我们正在探讨
换行。 \hfill \break
并组合两个命令
...
...

\begin{figure}
\centering
\includegraphics[width=3cm]{overleaf-logo}
\caption{Overleaf 标志}
\end{figure}

你好，这里有一些没有意义的文本...
\clearpage
```

![LineBreaksEx3OverleafNew.png](/files/3cfd3e742e5d5d411f439fe4fefac626be4bcd6c)

如果使用命令 `\clearpage` ，并且存在堆叠的浮动元素，例如表格或图形，它们会在开始新页面之前被清空。在上面的示例中，同一图像被插入了三次。由于分页是在所有图形显示之前插入的，剩余的图像会先插入到一个空白页中，然后再继续断点下方的文本。

如果这不是你需要的，可以使用 `\newpage` 代替。

```latex
\documentclass{article}
\usepackage[utf8]{inputenc}

\begin{document}
\documentclass{article}
\usepackage[utf8]{inputenc}

\begin{document}
本文档中的某些内容。这一段不包含任何信息，并且
其目的是提供一个如何插入空白
和换行的示例。\\
插入换行时，文本不会缩进，还有
几个额外的换行命令。 \newline
这一段完全没有信息。我们正在探讨
换行。 \hfill \break
并组合两个命令
...
...

\begin{figure}
\centering
\includegraphics[width=3cm]{overleaf-logo}
\caption{Overleaf 标志}
\end{figure}

你好，这里有一些没有意义的文本...
\newpage
```

![LineBreaksEx4Overleaf.png](/files/046c443cdac27aa5e5bdefef9af6fd200196d909)

在这种情况下，图像会被放在新页面中，并尽量适应文本流。

[在 Overleaf 中打开](https://www.overleaf.com/project/new/template/19338?id=65200057\&templateName=\&latexEngine=\&texImage=texlive-full%3A2020.1\&mainFile=)

## 水平空白

可以使用以下命令插入任意长度的水平空白： `\hspace`.

```latex
可以手动插入水平 \hspace{1cm} 空白。有助于
控制图片版式的细微调整。

左侧 \hfill 右侧
```

[在 Overleaf 中打开此示例](https://www.overleaf.com/docs?engine=\&snip_name=Horizontal+spaces\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cbegin%7Bdocument%7D%0A%0AHorizontal+%5Chspace%7B1cm%7D+spaces+can+be+inserted+manually.+Useful+%0Ato+control+the+fine-tuning+in+the+layout+of+pictures.%0A%0ALeft+Side+%5Chfill+Right+Side%0A%0A%5Cend%7Bdocument%7D)

![LineBreaksEx5.png](/files/c46aeddacb032c59382fb62002a348a04527953a)

在此示例中，有两个用于插入水平空白的命令：

**\hspace{1cm}**

插入一个长度为 1cm 的水平空白。该命令也可以使用其他 LaTeX 单位。

**\hfill**

插入一个会相应拉伸以填满可用空间的空白。

这些命令 `\hrulefill` 和 `\dotfill` 作用相同 `\hfill` 但它们插入的不是空白，而是分别一条水平横线和一串点。

## 垂直空白

垂直空白的语法与水平空白相同。

```latex
页面顶部的文本。页面顶部的文本。
页面顶部的文本。页面顶部的文本。
页面顶部的文本。页面顶部的文本。
页面顶部的文本。

\vspace{5mm} %5mm vertical space

这段文字仍在顶部，位于第一段下方 5 毫米处。

\vfill

页面底部的文本。
```

[在 Overleaf 中打开此示例](https://www.overleaf.com/docs?engine=\&snip_name=Vertical+blank+spaces\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cbegin%7Bdocument%7D%0A%0AText+at+the+top+of+the+page.+Text+at+the+top+of+the+page.+%0AText+at+the+top+of+the+page.+Text+at+the+top+of+the+page.+%0AText+at+the+top+of+the+page.+Text+at+the+top+of+the+page.+%0AText+at+the+top+of+the+page.%0A%0A%5Cvspace%7B5mm%7D+%255mm+vertical+space%0A%0AThis+text+still+at+the+top%2C+5mm+below+the+first+paragraph.%0A%0A%5Cvfill%0A%0AText+at+the+bottom+of+the+page.%0A%0A%5Cend%7Bdocument%7D)

![LineBreaksEx6.png](/files/395d9a58fa66372c9681edec4d45b63b7933fbc0)

让我们看看插入垂直空白的两个命令。

**\vspace{5mm}**

插入一个长度为 5mm 的垂直空白。该命令也可以使用其他 LaTeX 单位。

**\vfill**

插入一个会相应拉伸以填满可用垂直空间的空白。这就是为什么“页面底部的文本。”这一行会被移到最下方，而其余空间则被填满。

另外还有三个常用于插入垂直空白的命令

**\smallskip**

根据其他因素（文档类型、可用空间等），增加 3pt 的空白，上下浮动 1pt。

**\medskip**

根据其他因素（文档类型、可用空间等），增加 6pt 的空白，上下浮动 2pt。

**\bigskip**

根据其他因素（文档类型、可用空间等），增加 12pt 的空白，上下浮动 4pt。

## 参考指南

**其他换行命令**

* ```latex
   \\*
  ```

  （两个反斜杠和一个星号）

在命令所在处换行，并且额外禁止在该强制换行之后分页。

* ```latex
   \break
  ```

在不填满当前行的情况下换行。如果你不自己填满这一行，排版效果会很差。要填满这一行，可以像下面这样使用它。

* ```latex
   \hfill\break
  ```

这将产生与以下命令相同的效果： *\newline* 和 *\\\\*.

此外，LaTeX 还提供了以下用于换行的高级选项。

* ```latex
   \linebreak[number]
  ```

它在命令所在处换行。该 *number* 作为参数提供的数字表示该命令的优先级，范围为 0 到 4。（0 表示很容易被忽略，4 表示无论如何都要执行。）当使用此换行选项时，LaTeX 将尽量生成最佳的换行效果。

## 进一步阅读

更多信息请参见：

* [LaTeX 中的长度](/latex/zh-cn/ge-shi-hua/01-lengths-in-latex.md)
* [段落和换行](/latex/zh-cn/latex-ji-chu/02-paragraphs-and-new-lines.md)
* [段落格式设置](/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/zh-cn/latex-ji-chu/03-bold-italics-and-underlining.md)
* [列表](/latex/zh-cn/latex-ji-chu/04-lists.md)
* [单面和双面文档](/latex/zh-cn/ge-shi-hua/08-single-sided-and-double-sided-documents.md)
* [多栏排版](/latex/zh-cn/ge-shi-hua/09-multiple-columns.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/ge-shi-hua/05-line-breaks-and-blank-spaces.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.
