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

# 換行與空白

除非您正在 [建立巨集](/latex/zh-tw/lei-bie-dang/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/7142c534807d3aa8e1ef50c42b62eba34cc9ff58)

這並不是插入換行的唯一命令，在 [下一節](#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/5f81441d7e6d0aa15d912953890499efc51266b6)

這裡有三個命令在範例中的效果相同：

* `\\` （兩個反斜線）
* `\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/b9231f7116fc153ba6e75aa840b7e78ffb408432)

如果命令 `\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/99e93676c8fcb0c461145cb98b51bc79f72d4c67)

在這種情況下，圖片會被放到新頁面中，並盡量配合文字流排版。

[在 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/19584402754d3bae16f2ed1233792cd17c5cf154)

在此範例中，有兩個會插入水平空白的命令：

**\hspace{1cm}**

插入一段長度為 1cm 的水平空白。此命令也可使用其他 LaTeX 單位。

**\hfill**

插入一段可依可用空間伸縮以填滿空間的空白。

這些 `\hrulefill` 以及 `\dotfill` 與……的作用相同： `\hfill` 但不同的是，它們分別插入一條水平線與一串點。

## 垂直空白

垂直空白的語法與水平空白相同。

```latex
頁面頂端的文字。頁面頂端的文字。
頁面頂端的文字。頁面頂端的文字。
頁面頂端的文字。頁面頂端的文字。
頁面頂端的文字。

\vspace{5mm} %5mm 垂直空間

這段文字仍在頁面頂端，位於第一段下方 5mm。

\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/5bb5d26e83689ec81ac01d2b06d4c02fd64b6603)

來看看兩個插入垂直空白的命令。

**\vspace{5mm}**

插入一段長度為 5mm 的垂直空白。此命令也可使用其他 LaTeX 單位。

**\vfill**

插入一段可依可用的垂直空間伸縮以填滿空間的空白。這就是為什麼「Text at the bottom of the page.」會被移到頁面底部，而其餘空間則被填滿。

還有另外三個常用來插入垂直空白的命令

**\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-tw/ge-shi-hua/01-lengths-in-latex.md)
* [段落與換行](/latex/zh-tw/latex-ji-chu/02-paragraphs-and-new-lines.md)
* [段落格式](/latex/zh-tw/ge-shi-hua/04-articles-how-to-change-paragraph-spacing-in-latex.md)
* [文字對齊](/latex/zh-tw/ge-shi-hua/06-text-alignment.md)
* [粗體、斜體與底線](/latex/zh-tw/latex-ji-chu/03-bold-italics-and-underlining.md)
* [清單](/latex/zh-tw/latex-ji-chu/04-lists.md)
* [單面與雙面文件](/latex/zh-tw/ge-shi-hua/08-single-sided-and-double-sided-documents.md)
* [多欄](/latex/zh-tw/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://overleaf-pro.ayaka.space/latex/zh-tw/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.
