> 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/yu-yan/06-chinese.md).

# 中文

## 簡介

本文說明如何在 Overleaf 上排版中文文件。建議使用 XeLaTeX 或 LuaLaTeX 編譯器，因為它們可直接支援 UTF-8 編碼文字，並可搭配 TrueType 與 OpenType 字型。請參閱 [這篇文章](/latex/zh-tw/zhi-shi-ku/026-changing-compiler.md) 以了解如何在 Overleaf 中變更編譯器。

讓我們從一個使用 XeLaTeX 與 `ctexart` 文件類別的範例開始：

```latex
\documentclass{ctexart}
\begin{document}
\tableofcontents

\begin{abstract}
這是簡介及摘要。
\end{abstract}

\section{前言}

\section{關於數學部分}
數學、中英文皆可以混排。您可以在不新增額外環境的情況下，交錯排版數學、中文與英文（拉丁字母）。

這是繁體中文。
\end{document}
```

[在此開啟 `XeLaTeX` Overleaf 中的範例](https://www.overleaf.com/docs?engine=xelatex\&snip_name=Basic+example+of+the+ctexart+class\&snip=%5Cdocumentclass%7Bctexart%7D%0A%5Cbegin%7Bdocument%7D%0A%5Ctableofcontents%0A%0A%5Cbegin%7Babstract%7D%0A%E8%BF%99%E6%98%AF%E7%AE%80%E4%BB%8B%E5%8F%8A%E6%91%98%E8%A6%81%E3%80%82%0A%5Cend%7Babstract%7D%0A%0A%5Csection%7B%E5%89%8D%E8%A8%80%7D%0A%0A%5Csection%7B%E5%85%B3%E4%BA%8E%E6%95%B0%E5%AD%A6%E9%83%A8%E5%88%86%7D%0A%E6%95%B0%E5%AD%A6%E3%80%81%E4%B8%AD%E8%8B%B1%E6%96%87%E7%9A%86%E5%8F%AF%E4%BB%A5%E6%B7%B7%E6%8E%92%E3%80%82You+can+intersperse+math%2C+Chinese+and+English+%28Latin+script%29+without+adding+extra+environments.%0A%0A%E9%80%99%E6%98%AF%E7%B9%81%E9%AB%94%E4%B8%AD%E6%96%87%E3%80%82%0A%5Cend%7Bdocument%7D)

此範例會產生以下輸出：

![OL2Chinese1.png](/files/aa4c229c8b8bcf2e64fed6c7b476dbe30462f307)

該 `ctexart` 文件類別部分的 [`ctex` 套件套組](https://ctan.org/pkg/ctex?lang=en) ，它實作了常見的中文排版慣例。我們在下文會進一步討論 `ctex` 這些類別。

## ctex 類別

為了處理簡體中文排版的字元，你可以使用 `ctex` 文件類別： `ctexart`, `ctexrep`, `ctexbook` 以及 `ctexbeamer`。例如，要使用 `ctexart` 類別，請在文件導言區加入下列一行：

```latex
\documentclass{ctexart}
```

該 `ctexart` 類別（以及其他 `ctex` 類別）提供中文在地化，類似於 `babel`。你不僅能排版中文字符，還能定義像「Abstract」和「Table of Contents」這樣的元素，它們會被翻譯為「摘要」和「目錄」。

你可以將外部字型匯入文件中，方法是將它們上傳到與你的 LaTeX 檔案相同的目錄，或是使用系統層級的字型。例如，如果 `BabelStone Han` 字型已安裝在你的系統中，你可以在文件中使用

```latex
\setCJKmainfont{BabelStone Han}
```

文件中某些部分的其他字型也可以進行設定。若要為使用無襯線字型樣式的元素設定特定字型，請使用 `\setCJKsansfont{}` ；而對於以等寬字型顯示的元素，例如 verbatim 環境，請使用指令 `\setCJKmonofont{}`。你可以參考 Overleaf 上可用的中文字型清單 [這裡](/latex/zh-tw/wen-yu-da/85-which-otf-or-ttf-fonts-are-supported-via-fontspec.md#chinese).

請注意，範例中最後一行在 [導言](#introduction) 實際上使用的是繁體中文字元。這是由 Fandol 字型（預設）完成的，因為此字型包含這些字元。因此，使用正確的字型時，你其實可以用繁體與簡體中文來排版文件。不過，如果你使用只支援繁體或只支援簡體的字型，那麼沒有對應字形的字元就不會顯示在輸出的 PDF 中。

如果你需要使用像 `memoir` 這類文件類別， `.cls` 或是學校提供的論文 `ctex` ，但仍希望使用 `ctex` 套件套組，你可以載入

```latex
\documentclass{UniThesis}
\usepackage{ctex}
```

## 使用 XeLaTeX 搭配 xeCJK

如果完整的 `ctex` 在地化類別與套件感覺太大材小用，而你只想排版一些中文字符，那麼你可以使用 [`xeCJK` 套件](https://ctan.org/pkg/xecjk?lang=en)——但這只在使用 XeLaTeX 編譯時可行。

```latex
\documentclass{article}
\usepackage{xeCJK}
\begin{document}
\section{前言}
這是一些文字。

\section{關於數學部分}
數學、中英文皆可以混排。您可以在不新增額外環境的情況下，交錯排版數學、中文與英文（拉丁字母）。

這是繁體中文。
\end{document}
```

[在此開啟 `xeCJK` （XeLaTeX）在 Overleaf 中的範例](https://www.overleaf.com/docs?engine=xelatex\&snip_name=Basic+example+of+the+xeCJK+package\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%7BxeCJK%7D%0A%5Cbegin%7Bdocument%7D%0A%5Csection%7B%E5%89%8D%E8%A8%80%7D%0A%E8%BF%99%E6%98%AF%E4%B8%80%E4%BA%9B%E6%96%87%E5%AD%97%E3%80%82%0A%0A%5Csection%7B%E5%85%B3%E4%BA%8E%E6%95%B0%E5%AD%A6%E9%83%A8%E5%88%86%7D%0A%E6%95%B0%E5%AD%A6%E3%80%81%E4%B8%AD%E8%8B%B1%E6%96%87%E7%9A%86%E5%8F%AF%E4%BB%A5%E6%B7%B7%E6%8E%92%E3%80%82You+can+intersperse+math%2C+Chinese+and+English+%28Latin+script%29+without+adding+extra+environments.%0A%0A%E9%80%99%E6%98%AF%E7%B9%81%E9%AB%94%E4%B8%AD%E6%96%87%E3%80%82%0A%5Cend%7Bdocument%7D)

此範例會產生以下輸出：

![OL2Chinese2.png](/files/12ef5dadbc21e4e6d817af24c94c6317723c58e7)

## 使用 pdfLaTeX 搭配 CJKutf8

該 `CJKutf8` 套件可用於使用 pdfLaTeX 排版 CJK 語言。中文（以及日文／韓文）文字必須放在 `CJK` 環境中，因此這通常適合主要以拉丁字母為主的文件（例如英文）中包含中文片段（或反之亦然）。

```latex
\documentclass{article}
\usepackage{CJKutf8}
\begin{document}
\begin{CJK*}{UTF8}{gbsn}

\section{前言}

\section{關於數學部分}
數學、中英文皆可以混排。您可以在不新增額外環境的情況下，交錯排版數學、中文與英文（拉丁字母）。

\end{CJK*}

\bigskip  %% Just some white space

你也可以在文件中插入拉丁文字

\bigskip  %% Just some white space

\begin{CJK*}{UTF8}{bsmi}
這是繁體中文。
\end{CJK*}
\end{document}
```

[在此開啟 `CJKutf8` 套件範例（使用 pdfLaTeX）在 Overleaf 中](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Example+of+the+CJKutf8+package\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%7BCJKutf8%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cbegin%7BCJK%2A%7D%7BUTF8%7D%7Bgbsn%7D%0A%0A%5Csection%7B%E5%89%8D%E8%A8%80%7D%0A%0A%5Csection%7B%E5%85%B3%E4%BA%8E%E6%95%B0%E5%AD%A6%E9%83%A8%E5%88%86%7D%0A%E6%95%B0%E5%AD%A6%E3%80%81%E4%B8%AD%E8%8B%B1%E6%96%87%E7%9A%86%E5%8F%AF%E4%BB%A5%E6%B7%B7%E6%8E%92%E3%80%82You+can+intersperse+math%2C+Chinese+and+English+%28Latin+script%29+without+adding+extra+environments.%0A%0A%5Cend%7BCJK%2A%7D%0A%0A%5Cbigskip++%25%25+Just+some+white+space%0A%0AYou+can+also+insert+Latin+text+in+your+document%0A%0A%5Cbigskip++%25%25+Just+some+white+space%0A%0A%5Cbegin%7BCJK%2A%7D%7BUTF8%7D%7Bbsmi%7D%0A%E9%80%99%E6%98%AF%E7%B9%81%E9%AB%94%E4%B8%AD%E6%96%87%E3%80%82%0A%5Cend%7BCJK%2A%7D%0A%5Cend%7Bdocument%7D)

此範例會產生以下輸出：

![OL2Chinese3.png](/files/29dd9c78d98a58f0e77be6ee09cfd2ae77e56611)

這一行 `\usepackage{CJKutf8}` 匯入了 `CJKutf8` 套件，該套件可為中文、日文與韓文字型啟用 UTF-8 編碼。每一段中文都必須輸入在 `\begin{CJK*}{UTF8}{gbsn}` 環境中。在這個環境中 `UTF8` 是編碼，而 `gbsn` 是要使用的字型。你可以使用 `gbsn` 或 `gkai` 字型來排版簡體字元，並使用 `bsmi` 或 `bkai` 來排版繁體字元。

## 延伸閱讀

更多資訊請參見

* [以 XƎLaTeX 支援現代字型](/latex/zh-tw/zi-xing/03-xelatex.md)
* [Overleaf 上可用的中文字型](/latex/zh-tw/wen-yu-da/85-which-otf-or-ttf-fonts-are-supported-via-fontspec.md#chinese)
* [範例：在 Overleaf 上使用 CTeX 套件](https://www.overleaf.com/read/gndvpvsmjcqx)
* [範例：如何在 LaTeX 中以不同文字系統撰寫多語言文字](https://www.overleaf.com/read/wfdxqhcyyjxz)
* [引文與引號的排版](/latex/zh-tw/yu-yan/04-typesetting-quotations.md)
* [國際語言支援](/latex/zh-tw/yu-yan/03-international-language-support.md)
* [阿拉伯文](/latex/zh-tw/yu-yan/05-arabic.md)
* [法文](/latex/zh-tw/yu-yan/07-french.md)
* [德文](/latex/zh-tw/yu-yan/08-german.md)
* [希臘文](/latex/zh-tw/yu-yan/09-greek.md)
* [義大利文](/latex/zh-tw/yu-yan/10-italian.md)
* [日文](/latex/zh-tw/yu-yan/11-japanese.md)
* [韓文](/latex/zh-tw/yu-yan/12-korean.md)
* [葡萄牙文](/latex/zh-tw/yu-yan/13-portuguese.md)
* [俄文](/latex/zh-tw/yu-yan/14-russian.md)
* [西班牙文](/latex/zh-tw/yu-yan/15-spanish.md)
* [Ctex 套件文件](http://www.texdoc.net/pkg/ctex)
* [xeCJK 套件文件](http://www.texdoc.net/pkg/xeCJK)
* [LaTeX2ε 的不算太短的入門介紹](http://www.ctan.org/tex-archive/info/lshort/)
* [WikiBooks 上的 LaTeX/國際化](http://en.wikibooks.org/wiki/LaTeX/Internationalization)
* [WikiBooks 上的 LaTeX/特殊字元](http://en.wikibooks.org/wiki/LaTeX/Special_Characters)


---

# 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/yu-yan/06-chinese.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.
