Zum Inhalt springen

Introduction

This article explains how to typeset Chinese documents on Overleaf. The recommended approach is to use the XeLaTeX or LuaLaTeX compilers because they directly support UTF-8 encoded text and work with TrueType and OpenType fonts. See this article to learn how to change the compiler in Overleaf.

Let’s start with an example which uses XeLaTeX and the ctexart document class:

\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}

 Open this XeLaTeX example in Overleaf

This example produces the following output:

OL2Chinese1.png

The ctexart document class part of the ctex package bundle which implements common Chinese typesetting practices. We discuss further details about the ctex classes below.

The ctex classes

In order to handle characters for Simplified Chinese typesetting you can use the ctex document classes: ctexart, ctexrep, ctexbook and ctexbeamer. For example, to use the ctexart class include the following line in your document preamble:

\documentclass{ctexart}

The ctexart class (and other ctex classes) provides Chinese localisation, much like babel. You will not only be able to typeset Chinese characters, but also define elements such as “Abstract” and “Table of Contents” that will be translated as 摘要 and 目录.

You can import external fonts to your document, either uploading them to the same directory of your LaTeX file, or using system-wide fonts. For instance, if the BabelStone Han font is already installed on your system, you can use it in your document with

\setCJKmainfont{BabelStone Han}

Additional fonts for some parts of the document can be configured. To set a specific font for elements that use a sans serif font style use \setCJKsansfont{} and for elements that are displayed in a monospace font, such as verbatim environments, use the command \setCJKmonofont{}. You can refer to the list of Chinese fonts available on Overleaf here.

Notice that the last line in the example at the introduction is actually using Traditional Chinese characters. This is accomplished by the Fandol font (the default) because this font includes them. So, with the right font, you can actually typeset your document in both Simplified and Traditional Chinese. If you use a traditional- or simplified-only font, though, then characters whose glyphs are not available would not show up in the output PDF.

If you need to use document class such as memoir or perhaps a thesis .cls provided by your university, but would still like to use the ctex bundle, you can load the ctex package, like this:

\documentclass{UniThesis}
\usepackage{ctex}

xeCJK with XeLaTeX

If the complete ctex localisation classes and package feels like an overkill, and you just want to typeset some Chinese characters, you can use the xeCJK package—which only works when compiled with XeLaTeX.

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

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

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

 Open this xeCJK (XeLaTeX) example in Overleaf

This example produces the following output:

OL2Chinese2.png

Using CJKutf8 with pdfLaTeX

The CJKutf8 package can be used to typeset CJK languages with pdfLaTeX. Chinese (and Japanese/Korean) text must be placed inside a CJK environment, so this is usually convenient for primarily Latin-based documents (e.g., English) which contain fragments of Chinese text (or vice-versa).

\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  %% Just some white space

You can also insert Latin text in your document

\bigskip  %% Just some white space

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

 Open this CJKutf8 package example (using pdfLaTeX) in Overleaf

This example produces the following output:

OL2Chinese3.png

The line \usepackage{CJKutf8} imports the CJKutf8 package which enables UTF-8 encoding for use with Chinese, Japanese and Korean fonts. Every block of Chinese text must be typed inside a \begin{CJK*}{UTF8}{gbsn} environment. In this environment UTF8 is the encoding and gbsn is the font to be used. You can use gbsn or gkai fonts for Simplified characters, and bsmi or bkai for Traditional characters.

Further reading

For more information see

Overleaf guides

LaTeX Basics

Mathematics

Figures and tables

References and Citations

Languages

Document structure

Formatting

Fonts

Presentations

Commands

Field specific

Class files

Advanced TeX/LaTeX