> 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/06-text-alignment.md).

# 文字對齊

## 簡介

預設情況下，LaTeX 會將文字排成兩端對齊，但有時候左對齊或「右邊參差不齊」的文字（用於從右到左的語言）可能更適合——例如窄欄中的文字。本文說明如何使用 LaTeX 內建功能以及套件來變更文件部分或全部內容的文字對齊方式 `ragged2e`.

## 標準的 LaTeX 指令與環境

LaTeX 的確有用來變更文字排版對齊方式的內建指令：

* 參差右對齊（`\raggedright`)
* 參差左對齊（`\raggedleft`)
* 置中（`\centering`)

以及對應的環境：

* 參差右對齊（`flushleft` 環境）
* 參差左對齊（`flushright` 環境）
* 置中（`centering` 環境）

然而， [`ragged2e` 套件](https://ctan.org/pkg/ragged2e?lang=en) 提供了一些改良功能，可優於這些標準的 LaTeX 指令與環境。

## 使用 ragged2e 套件

先從一個使用 `ragged2e` 套件及其 `[document]` 選項來排版 *整份文件文字* 為參差右對齊（左對齊）。範例程式碼加入了這一行

```latex
\usepackage[document]{ragged2e}
```

到文件前言中：

```latex
\documentclass{article}
\usepackage[document]{ragged2e}

\begin{document}
\section{第一層標題（section）}
你好，這裡有一些沒有意義的文字。這段文字應該顯示印刷後的文字在此處會是什麼樣子。如果你閱讀這段文字，你不會得到任何資訊。真的嗎？真的沒有資訊嗎？這段文字和像完全沒有這回事之類的胡言亂語有什麼差別嗎！像這樣的無意義文字能讓你了解所選字型、字母如何書寫，以及整體外觀的印象。
\end{document}
```

[在此開啟 `ragged2e` Overleaf 中的範例](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Example+using+ragged2e+package\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%5Bdocument%5D%7Bragged2e%7D%0A%0A%5Cbegin%7Bdocument%7D%0A%5Csection%7BHeading+on+Level+1+%28section%29%7D%0AHello%2C+here+is+some+text+without+a+meaning.+This+text+should+show+what+a+printed+text+will+look+like+at+this+place.++If+you+read+this+text%2C+you+will+get+no+information.++Really%3F++Is+there+no+information%3F++Is+there+a+difference+between+this+text+and+some+nonsense+like+not+at+all%21++A+blind+text+like+this+gives+you+information+about+the+selected+font%2C+how+the+letters+are+written+and+an+impression+of+the+look.%0A%5Cend%7Bdocument%7D)

此範例會產生以下輸出：

![Ragged2eOLV21.png](/files/f31048f0aa80c434b1329d870ebb88f52ff3b5f4)

## 比較 \raggedright（LaTeX）與 \RaggedRight（ragged2e）

LaTeX 指令 `\raggedright` 有時會產生看起來「過於參差」的結果。套件 `ragged2e` 透過在某一行太短時允許斷字來解決這個問題，產生更均勻的參差文字邊緣。下列範例顯示使用 LaTeX 指令產生的參差右對齊文字 `\raggedright` 以及，作為比較，使用 `\RaggedRight` 所提供的指令 `ragged2e`:

```latex
\documentclass{article}
\usepackage[english]{babel}
\usepackage{ragged2e}
\usepackage{blindtext}

\begin{document}
\setlength{\hsize}{0.9\hsize}% 強調效果

\subsection*{使用 \texttt{\string\raggedright} 的左對齊範例\\（標準 \LaTeX{} 指令）}
\raggedright\blindtext[2]\par
\subsection*{使用 \texttt{\string\RaggedRight} 的左對齊範例\\（\texttt{ragged2e} 指令）}

\RaggedRight\blindtext[2]\par
Leftaligncompare2.png
\end{document}
```

[在 Overleaf 中開啟此範例](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Demonstrating+left-aligned+text\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%5Benglish%5D%7Bbabel%7D%0A%5Cusepackage%7Bragged2e%7D%0A%5Cusepackage%7Bblindtext%7D%0A%0A%5Cbegin%7Bdocument%7D%0A%5Csetlength%7B%5Chsize%7D%7B0.9%5Chsize%7D%25+emphasize+effects%0A%0A%5Csubsection%2A%7BLeft-aligned+example+with+%0A%5Ctexttt%7B%5Cstring%5Craggedright%7D%5C%5C+%28standard+%5CLaTeX%7B%7D+command%29%7D%0A%5Craggedright%5Cblindtext%5B2%5D%5Cpar%0A%0A%5Csubsection%2A%7BLeft-aligned+example+with+%5Ctexttt%7B%5Cstring%5CRaggedRight%7D%5C%5C+%28%5Ctexttt%7Bragged2e%7D+command%29%7D%0A%5CRaggedRight%5Cblindtext%5B2%5D%5Cpar+%0A%5Cend%7Bdocument%7D)

![Leftaligncompare2.png](/files/4ee818c90c20b347a9a2760c15a6a014e4afca28)

如同在 `ragged2e` [套件文件所述](https://mirror.ox.ac.uk/sites/ctan.org/macros/latex/contrib/ragged2e/ragged2e.pdf), `ragged2e` 中所討論的，提供了可修改文字對齊方式的替代指令與環境，我們將看看其中一些。

## 參差右對齊（左對齊）文字的環境

產生參差右對齊文字的預設 LaTeX 環境是 `flushleft`。在 `ragged2e` 中稱為 `FlushLeft` （請注意大小寫）。以下範例比較這些環境的輸出：

```latex
\documentclass{article}
\usepackage[english]{babel}
\usepackage{ragged2e}
\usepackage{blindtext}
\begin{document}
\setlength{\hsize}{0.9\hsize}% 強調效果

\subsection*{\texttt{flushleft} 環境：（標準 \LaTeX{}）}

\begin{flushleft}
\blindtext[1]
\end{flushleft}

\subsection*{\texttt{FlushLeft} 環境：（\texttt{ragged2e}）}

\begin{FlushLeft}
\blindtext[1]
\end{FlushLeft}

\end{document}
```

[在 Overleaf 中開啟此範例](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Demonstrating+left-aligned+text\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%5Benglish%5D%7Bbabel%7D%0A%5Cusepackage%7Bragged2e%7D%0A%5Cusepackage%7Bblindtext%7D%0A%5Cbegin%7Bdocument%7D%0A%5Csetlength%7B%5Chsize%7D%7B0.9%5Chsize%7D%25+emphasize+effects%0A%0A%5Csubsection%2A%7B%5Ctexttt%7Bflushleft%7D+environment%3A+%28standard+%5CLaTeX%7B%7D%29%7D%0A%0A%5Cbegin%7Bflushleft%7D%0A%5Cblindtext%5B1%5D%0A%5Cend%7Bflushleft%7D%0A%0A%5Csubsection%2A%7B%5Ctexttt%7BFlushLeft%7D+environment%3A+%28%5Ctexttt%7Bragged2e%7D%29%7D%0A%0A%5Cbegin%7BFlushLeft%7D%0A%5Cblindtext%5B1%5D%0A%5Cend%7BFlushLeft%7D%0A%0A%5Cend%7Bdocument%7D)

![Flcompare.png](/files/c01eceebee58c978874077e050cb974e13062f60)

## 參差左對齊（右對齊）文字的環境

產生參差左對齊（右對齊）文字的預設 LaTeX 環境是 `flushright`。在 `ragged2e` 中稱為 `FlushRight` （請注意大小寫）。以下範例比較這些環境的輸出：

```latex
\documentclass{article}
\usepackage[english]{babel}
\usepackage{ragged2e}
\usepackage{blindtext}
\begin{document}
\setlength{\hsize}{0.9\hsize}% 強調效果

\subsection*{\texttt{flushright} 環境：（標準 \LaTeX{}）}

\begin{flushright}
\blindtext[1]
\end{flushright}

\subsection*{\texttt{FlushRight} 環境：（\texttt{ragged2e}）}

\begin{FlushRight}
\blindtext[1]
\end{FlushRight}

\end{document}
```

[在 Overleaf 中開啟此範例](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Demonstrating+right-aligned+text\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%5Benglish%5D%7Bbabel%7D%0A%5Cusepackage%7Bragged2e%7D%0A%5Cusepackage%7Bblindtext%7D%0A%5Cbegin%7Bdocument%7D%0A%5Csetlength%7B%5Chsize%7D%7B0.9%5Chsize%7D%25+emphasize+effects%0A%0A%5Csubsection%2A%7B%5Ctexttt%7Bflushright%7D+environment%3A+%28standard+%5CLaTeX%7B%7D%29%7D%0A%0A%5Cbegin%7Bflushright%7D%0A%5Cblindtext%5B1%5D%0A%5Cend%7Bflushright%7D%0A%0A%5Csubsection%2A%7B%5Ctexttt%7BFlushRight%7D+environment%3A+%28%5Ctexttt%7Bragged2e%7D%29%7D%0A%0A%5Cbegin%7BFlushRight%7D%0A%5Cblindtext%5B1%5D%0A%5Cend%7BFlushRight%7D%0A%0A%5Cend%7Bdocument%7D)

![FRcompare.png](/files/cf0631034c6985b872dcff89ee6b74ab3471e5a8)

## 使文字置中的環境

產生置中文字的預設 LaTeX 環境是 `center`。在 `ragged2e` 中稱為 `Center` （請注意大小寫）。以下範例比較這些環境的輸出：

```latex
\documentclass{article}
\usepackage[english]{babel}
\usepackage{ragged2e}
\usepackage{blindtext}
\begin{document}
\setlength{\hsize}{0.9\hsize}% 強調效果

\subsection*{\texttt{center} 環境：（標準 \LaTeX{}）}

\begin{center}
\blindtext[1]
\end{center}

\subsection*{\texttt{Center} 環境：（\texttt{ragged2e}）}
\begin{Center}
\blindtext[1]
\end{Center}
\end{document}
```

[在 Overleaf 中開啟此範例](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Demonstrating+right-aligned+text\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%5Benglish%5D%7Bbabel%7D%0A%5Cusepackage%7Bragged2e%7D%0A%5Cusepackage%7Bblindtext%7D%0A%5Cbegin%7Bdocument%7D%0A%5Csetlength%7B%5Chsize%7D%7B0.9%5Chsize%7D%25+emphasize+effects%0A%0A%5Csubsection%2A%7B%5Ctexttt%7Bcenter%7D+environment%3A+%28standard+%5CLaTeX%7B%7D%29%7D%0A%0A%5Cbegin%7Bcenter%7D%0A%5Cblindtext%5B1%5D%0A%5Cend%7Bcenter%7D%0A%0A%5Csubsection%2A%7B%5Ctexttt%7BCenter%7D+environment%3A+%28%5Ctexttt%7Bragged2e%7D%29%7D%0A%5Cbegin%7BCenter%7D%0A%5Cblindtext%5B1%5D%0A%5Cend%7BCenter%7D%0A%5Cend%7Bdocument%7D)

![Centrecompare.png](/files/1cb5b7bcaafdae1854e9577ca88d795ed3b72e9e)

## 兩端對齊文字

套件 `ragged2e` 提供了指令 `\justifying` 您可以如下方範例所示使用：

```latex
\documentclass{article}
\usepackage[english]{babel}
\usepackage{ragged2e}
\usepackage{blindtext}
\begin{document}
\setlength{\hsize}{0.9\hsize}% 強調效果

\Centering
\blindtext[1]

\vspace{5mm}
\justifying
\blindtext[1]
\end{document}
```

[在 Overleaf 中開啟此範例](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Demonstrating+justification+with+ragged2e\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%5Benglish%5D%7Bbabel%7D%0A%5Cusepackage%7Bragged2e%7D%0A%5Cusepackage%7Bblindtext%7D%0A%5Cbegin%7Bdocument%7D%0A%5Csetlength%7B%5Chsize%7D%7B0.9%5Chsize%7D%25+emphasize+effects%0A%0A%5CCentering%0A%5Cblindtext%5B1%5D%0A%0A%5Cvspace%7B5mm%7D%0A%5Cjustifying%0A%5Cblindtext%5B1%5D+%0A%5Cend%7Bdocument%7D)

![Justifyingdemo.png](/files/1765b87934a61e268c23cf87960792a6834ead70)

## 參考指南

**文字對齊的環境與指令摘要**

| 對齊方式 | 環境           | 切換指令           | ragged2e 環境  | ragged2e 切換指令  |
| ---- | ------------ | -------------- | ------------ | -------------- |
| 左    | `flushleft`  | `\raggedright` | `FlushLeft`  | `\RaggedRight` |
| 右    | `flushright` | `\raggedleft`  | `FlushRight` | `\RaggedLeft`  |
| 中    | `center`     | `\centering`   | `Center`     | `\Centering`   |
| 兩端對齊 |              |                | `justify`    | `\justifying`  |

## 延伸閱讀

更多資訊請參閱：

* [段落與換行](/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/latex-ji-chu/03-bold-italics-and-underlining.md)
* [字型大小、字族與樣式](/latex/zh-tw/zi-xing/01-font-sizes-families-and-styles.md)
* [字型字體](/latex/zh-tw/zi-xing/02-font-typefaces.md)
* [使用 XeLaTeX 支援現代字型](/latex/zh-tw/zi-xing/03-xelatex.md)
* [換行與空白](/latex/zh-tw/ge-shi-hua/05-line-breaks-and-blank-spaces.md)
* [清單](/latex/zh-tw/latex-ji-chu/04-lists.md)
* [章節與章](/latex/zh-tw/wen-jian-jie-gou/01-sections-and-chapters.md)
* [多欄](/latex/zh-tw/ge-shi-hua/09-multiple-columns.md)
* [單面與雙面文件](/latex/zh-tw/ge-shi-hua/08-single-sided-and-double-sided-documents.md)
* [LaTeX2ε 的不算太短的入門介紹](http://www.ctan.org/tex-archive/info/lshort/)
* [ragged2e 套件文件](http://mirror.hmc.edu/ctan/macros/latex/contrib/ms/ragged2e.pdf)


---

# 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/06-text-alignment.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.
