企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
由于新的中英混排方法的引入,这里对于每一个效果提供两份代码(如果有必要)。如果没有特别的需求,应当使用新方法。 ## 作者、标题、日期 保存并用 XeLaTeX 编译如下文档,查看效果: 新方法: ~~~ \documentclass[UTF8]{ctexart} \title{你好,world!} \author{Liam} \date{\today} \begin{document} \maketitle 你好,world! \end{document} ~~~ 旧方法: ~~~ \documentclass{article} % % 设置中文字体 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \usepackage[SlantFont,BoldFont,CJKchecksingle,CJKnumber]{xeCJK} \newcommand\fontnamehei{SimHei}% 黑体 \newcommand\fontnamesong{SimSun}% 宋体 \newcommand\fontnamekai{KaiTi_GB2312}% 楷体 \newcommand\fontnameyahei{Yahei Mono}% 雅黑 \defaultfontfeatures{Mapping=tex-text} \setCJKmainfont[BoldFont=\fontnamehei,ItalicFont=\fontnamekai]{\fontnamesong} \setCJKmonofont{\fontnameyahei} \setCJKsansfont[BoldFont=\fontnamehei]{\fontnameyahei} % % 设置标题、作者、日期 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \title{你好,world!} \author{Liam} \date{\today} \begin{document} \maketitle 你好,world! \end{document} ~~~ 导言区复杂了很多,但和之前的文档主要的区别只有两处(新方法只有一处,此处第 2 条)。 1. 深入定义了中文字体以及断行逻辑; * 调用`xeCJK`宏包的时候,添加了一些可选参数; * 使用`\newcommand`命令,将系统字体名映射为相应的命令,方便维护; * 在定义主字体的时候,用`[]`添加了一些可选参数,增强功能。 2. 定义了 标题、作者、日期。 在`document`环境中,除了原本的`你好,world!`,还多了一个控制序列`maketitle`。这个控制序列能将在导言区中定义的 标题、作者、日期 按照预定的格式展现出来。 > 使用`titling`宏包可以修改上述默认格式。参考[TeXdoc](http://texdoc.net/texmf-dist/doc/latex/titling/titling.pdf). ## 章节和段落 保存并用 XeLaTeX 编译如下文档,查看效果: 新方法: ~~~ \documentclass[UTF8]{ctexart} \title{你好,world!} \author{Liam} \date{\today} \begin{document} \maketitle \section{你好中国} 中国在 East Asia. \subsection{Hello Beijing} 北京是 capital of China. \subsubsection{Hello Dongcheng District} \paragraph{Tian'anmen Square} is in the center of Beijing \subparagraph{Chairman Mao} is in the center of 天安门广场。 \subsection{Hello 山东} \paragraph{山东大学} is one of the best university in 山东。 \end{document} ~~~ 旧方法: ~~~ \documentclass{article} % % 设置中文字体 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \usepackage[SlantFont,BoldFont,CJKchecksingle,CJKnumber]{xeCJK} \newcommand\fontnamehei{SimHei} \newcommand\fontnamesong{SimSun} \newcommand\fontnamekai{KaiTi_GB2312}%KaiTi \newcommand\fontnameyahei{Yahei Mono} \defaultfontfeatures{Mapping=tex-text} \setCJKmainfont[BoldFont=\fontnamehei,ItalicFont=\fontnamekai]{\fontnamesong} \setCJKmonofont{\fontnameyahei} \setCJKsansfont[BoldFont=\fontnamehei]{\fontnameyahei} % % 设置标题、作者、日期 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \title{你好,world!} \author{Liam} \date{\today} \begin{document} \maketitle \section{你好中国} 中国在East Asia. \subsection{Hello Beijing} 北京是 capital of China. \subsubsection{Hello Dongcheng District} \paragraph{Tian'anmen Square} is in the center of Beijing \subparagraph{Chairman Mao} is in the center of 天安门广场。 \subsection{Hello 山东} \paragraph{山东大学} is one of the best university in 山东。 \end{document} ~~~ 在文档类 `article`/`ctexart` 中,定义了五个控制序列来调整行文组织结构。他们分别是 * `\section{·}` * `\subsection{·}` * `\subsubsection{·}` * `\paragraph{·}` * `\subparagraph{·}` > 在`report`/`ctexrep`中,还有`\chapter{·}`;在文档类`book`/`ctexbook`中,还定义了`\part{·}`。 ## 插入目录 在上一节的文档中,找到`\maketitle`,在它的下面插入控制序列`\tableofcontents`,保存并用 XeLaTeX 编译两次,观察效果: 新方法: ~~~ \documentclass[UTF8]{ctexart} \title{你好,world!} \author{Liam} \date{\today} \begin{document} \maketitle \tableofcontents \section{你好中国} 中国在 East Asia. \subsection{Hello Beijing} 北京是 capital of China. \subsubsection{Hello Dongcheng District} \paragraph{Tian'anmen Square} is in the center of Beijing \subparagraph{Chairman Mao} is in the center of 天安门广场。 \subsection{Hello 山东} \paragraph{山东大学} is one of the best university in 山东。 \end{document} ~~~ 旧方法: ~~~ \documentclass{article} % % 设置中文字体 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \usepackage[SlantFont,BoldFont,CJKchecksingle,CJKnumber]{xeCJK} \newcommand\fontnamehei{SimHei} \newcommand\fontnamesong{SimSun} \newcommand\fontnamekai{KaiTi_GB2312}%KaiTi \newcommand\fontnameyahei{Yahei Mono} \defaultfontfeatures{Mapping=tex-text} \setCJKmainfont[BoldFont=\fontnamehei,ItalicFont=\fontnamekai]{\fontnamesong} \setCJKmonofont{\fontnameyahei} \setCJKsansfont[BoldFont=\fontnamehei]{\fontnameyahei} % % 设置标题、作者、日期 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \title{你好,world!} \author{Liam} \date{\today} \begin{document} \maketitle \tableofcontents \section{你好中国} 中国在East Asia. 中国在East Asia. \subsection{Hello Beijing} 北京是 capital of China. \subsubsection{Hello Dongcheng District} \paragraph{Tian'anmen Square} is in the center of Beijing \subparagraph{Chairman Mao} is in the center of 天安门广场。 \subsection{Hello 山东} \paragraph{山东大学} is one of the best university in 山东。 \end{document} ~~~ > 试试交换`\maketitle`和`\tableofcontents`的顺序,看看会发生什么。 请注意,在“你好中国”这一节中,两次“中国在 East Asia.”中夹有一个空行,但输出却只有一个换行并没有空行。这是因为 LaTeX 将一个换行当做是一个简单的空格来处理,如果需要换行另起一段,则需要用两个换行(一个空行)来实现。