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

# 中文

## 引言

本文介绍如何在 Overleaf 上排版中文文档。推荐使用 XeLaTeX 或 LuaLaTeX 编译器，因为它们直接支持 UTF-8 编码文本，并且可与 TrueType 和 OpenType 字体配合使用。参见 [这篇文章](/latex/zh-cn/zhi-shi-ku/026-changing-compiler.md) 了解如何在 Overleaf 中更改编译器。

让我们从一个使用 XeLaTeX 和 `ctexart` 文档类的示例开始：

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

\begin{abstract}
这是简介及摘要。
\end{abstract}

\section{前言}

\section{关于数学部分}
数学、中英文皆可以混排。You can intersperse math, Chinese and English (Latin script) without adding extra environments.

这是繁体中文。
\end{document}
```

[在 Overleaf 中打开此 `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/47e31a6cecc75363d1e101f7c938f4b72dd52baa)

该 `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-cn/wen-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{关于数学部分}
数学、中英文皆可以混排。You can intersperse math, Chinese and English (Latin script) without adding extra environments.

这是繁体中文。
\end{document}
```

[在 Overleaf 中打开此 `xeCJK` Overleaf 中的（XeLaTeX）示例](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/54064836a6b72b9de768e680cbfde3904899d431)

## 在 pdfLaTeX 中使用 CJKutf8

该 `CJKutf8` 宏包可用于在 pdfLaTeX 中排版 CJK 语言。中文（以及日文/韩文）文本必须放在一个 `CJK` 环境中，因此这通常适用于以拉丁字母为主的文档（例如英语），其中包含少量中文文本（或反之亦然）。

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

\section{前言}

\section{关于数学部分}
数学、中英文皆可以混排。You can intersperse math, Chinese and English (Latin script) without adding extra environments.

\end{CJK*}

\bigskip  %% 只是一些空白

你也可以在文档中插入拉丁文本

\bigskip  %% 只是一些空白

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

[在 Overleaf 中打开此 `CJKutf8` Overleaf 中的宏包示例（使用 pdfLaTeX）](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/c9d6114df1c5925d12b952b25bcf9563d571a688)

这一行 `\usepackage{CJKutf8}` 导入 `CJKutf8` 宏包，它启用了 UTF-8 编码，以便与中文、日文和韩文字体一起使用。每一块中文文本都必须输入在一个 `\begin{CJK*}{UTF8}{gbsn}` 环境中。在此环境中 `UTF8` 是编码，而 `gbsn` 是要使用的字体。你可以使用 `gbsn` 或 `gkai` 字体用于简体字符，而 `bsmi` 或 `bkai` 字体用于繁体字符。

## 进一步阅读

更多信息请参见

* [使用 XƎLaTeX 支持现代字体](/latex/zh-cn/zi-ti/03-xelatex.md)
* [Overleaf 上可用的中文字体](/latex/zh-cn/wen-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-cn/yu-yan/04-typesetting-quotations.md)
* [国际语言支持](/latex/zh-cn/yu-yan/03-international-language-support.md)
* [阿拉伯语](/latex/zh-cn/yu-yan/05-arabic.md)
* [法语](/latex/zh-cn/yu-yan/07-french.md)
* [德语](/latex/zh-cn/yu-yan/08-german.md)
* [希腊语](/latex/zh-cn/yu-yan/09-greek.md)
* [意大利语](/latex/zh-cn/yu-yan/10-italian.md)
* [日语](/latex/zh-cn/yu-yan/11-japanese.md)
* [韩语](/latex/zh-cn/yu-yan/12-korean.md)
* [葡萄牙语](/latex/zh-cn/yu-yan/13-portuguese.md)
* [俄语](/latex/zh-cn/yu-yan/14-russian.md)
* [西班牙语](/latex/zh-cn/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-cn/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.
