如何使用latex来写中文文档。

如何使用latex来写中文文档。

两大类、共计三种方法。

第一类:Using the engine TeX/pdfTeX (original LaTeX and pdfLaTeX)

使用The CJK package

示例:

\documentclass{article}

\usepackage{CJK}

\begin{document}

\begin{CJK}{GBK}{song}

汉字

\end{CJK}

\end{document}

该方法因为食用不方便已经被淘汰了。

第二类:Using the engine XeTeX

有两种package可以使用:xeCJK 和 ctex。

tex给中文字符排版的过程可以大致分为三部分:选择字体,处理禁止命令和处理布局。

使用XeLaTeX加上包xeCJK可以处理前两个过程,使用XeLaTex加上包ctex可以很好地处理最后一个部分。

(a)使用xeCJK包

Example:

\documentclass{article}

\usepackage{metalogo} % for the logo of XeLaTeX

\usepackage{showframe} % for showing page frames

\usepackage{xeCJK}

\setCJKmainfont{Adobe Heiti Std}

\begin{document}

这里是中文,这是黑体。我在使用\XeLaTeX 结合xeCJK排版中文。

\end{document}

Tips:

You do not need to add ~ between CJK character and western character to regulate the space between them, as you always did in CJK/CJKutf8.

With the engine XeTeX, CJK character can be used as a command, so you must leave a space after any command, if it is followed by any CJK character, or an Undefined control sequence error will be reported.

(b)使用ctex包

1)使用方式不是直接使用ctex包,而是设置文档类别为ctex提供的标准中文文档类

\documentclass[UTF8]{ctexart} % instead of `article’

This package set SimSun/KaiTi, provided by china-e(中易中标电子信息技术有限公司), as default fonts for user in China mainland, using Windows OS, CN-Simp version. If you have installed these fonts correctly, typesetting Chinese becomes quite easily.

%!TEX program = xelatex

\documentclass[UTF8]{ctexart} % instead of `article’

% `ctexbook’ for `book’, and `ctexrep’ for `report’

\begin{document}

这里是中文。\\

段首缩进两个字符宽度。

这里是默认字体,中易宋体。\textit{这里是楷书},\texttt{还有仿宋}。

\end{document}

If you do not have these fonts, using the nofonts option and selecting fonts manually will be a good choice. Here’s a example (without text body):

\documentclass[UTF8, nofonts]{ctexart} 

% select fonts for western chars

\setmainfont{TeX Gyre Termes}

\setsansfont{TeX Gyre Termes}

% select fonts for CJK chars

\setCJKmainfont[BoldFont={Adobe Heiti Std},ItalicFont={Adobe Kaiti Std}]{Adobe Song Std}

\setCJKsansfont{Adobe Heiti Std}

\setCJKmonofont{Adobe Fangsong Std}

\begin{document}

这里是中文。\\

段首缩进两个字符宽度。

\emph{hello world} hello world!

\textbf{中文}

\emph{中文}

\end{document}

ctexart, ctexrep, ctexbook, ctexbeamer是ctex提供的四个中文文档类,分别对应了LATEX的标准文档类article, report, book, beamer。使用它们的时候将涉及到的所有源文件使用UTF-8编码保存。

2)如果不使用ctex提供的中文文档类的话,可以在其他文档类中使用ctex宏包。

如在非ctex标准文档类中使用ctex宏包将章节标题设置为中文风格。

\documentclass{ltxdoc} \usepackage[UTF8, heading = true]{ctex}

\begin{document}

\section{简介}

章节标题中文化的 \LaTeX{} 手册。 

\end{document}

可以使用\ctexset命令设置ctex宏包选项。

\ctexset {<key1>=<value1>,…}

举例:

\ctexset{

abstractname = {本文概要},

bibname = {文\quad 献}

}

设置字体大小:

\ctexset{zihao=-4}%设置小四号字体


版权声明:本文为u014791046原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。