LaTeX supports many worldwide languages by means of some special packages. This article explains how to typeset Chinese documents on Overleaf.
The recommended approach is to use the XƎLaTeX or LuaLaTeX compilers, as they support UTF-8 directly and allows more flexibility to work with true type and opentype fonts. See this article to learn how to change the compiler in Overleaf.
\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}
The ctexart
document class here is provided by the ctex
bundle, which implements common Chinese typesetting practices. We discuss further details about the ctex
classes below.
Modern computer systems allow you to input letters of national alphabets directly from the keyboard. In order to handle characters for Simplified Chinese typesetting you can use the ctex document classes: ctexart
, ctexrep
, ctexbook
and ctexbeamer
.
\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 the "Table of Contents" that will be properly 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 established. To set a specific font for elements that use sans font style use \setCJKsansfont{}
and for elements that are displayed in 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.
You may sometimes be using a different document class e.g. memoir
or a thesis .cls
provided by your university, but would still like like to use the ctex
bundle. You can load the ctex
package in this case:
\documentclass{UniThesis}
\usepackage{ctex}
If the complete localisation ctex
classes and package feels like an overkill and you just want to typeset some Chinese characters, you can use the xeCJK
package.
\documentclass{article}
\usepackage{xeCJK}
\begin{document}
\section{前言}
\section{关于数学部分}
数学、中英文皆可以混排。You can intersperse math, Chinese and English (Latin script) without adding extra environments.
這是繁體中文。
\end{document}
The xeCJK package only works when compiled with XƎLaTeX.
The CJKutf8
package can also be used to generate a document with pdfLaTeX. Chinese (and Japanese/Korean) text must be placed inside a CJK
environment, so this is usually only convenient for documents in English with bits 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}
The line \usepackage{CJKutf8}
imports CJKutf8 which enables utf8 encoding for Chinese, Japanese and Korean fonts.
In this case 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.
For more information see