目录
- Step 0. 配置LaTeX
- Step 1. 使用LaTeX做Routine Work
- Step 2. 支持中文
- Step 3. 论文编辑的常用元素
- Step 4. 段落,段落格式和目录
- Step 5. 图片
- Step 6. 页面设置
- Step 7. 模板
- Step inf. 额外说明
TeX是由高德纳开发的一款排版引擎,由于纯TeX过于底层,所以很多人选择使用LaTeX,LaTeX是TeX的一个常用宏包。一般来说在使用LaTeX时写论文时,官方都会给一套现成的模板,我们按照上面的说明用就行。但有些先验知识我们还是要先学习的。
Step 0. 配置LaTeX
Windows下常用的LaTeX命令行工具是MikTeX,不过我们一般直接使用CTEX整合包。特别需要注意的是CTEX的安装过程会重置Windows的环境变量,所以一定要注意先行保存!另外需要提及的就是各种LateX的IDE了,常用的有TexStudio、TeXMaker等,其实差别不大。下面以TeXStuido为主介绍。
TeXStudio
TeXStudio是一个的界面还是比较简单容易操作的。
其中配置常出现以下问题:
- Make sure that you have installed a (La)TeX distribution

这是因为没有没有安装LaTeX发行版的缘故,TeXStudio是一个可配置的LaTeX编辑器,我们需要单独安装对应的编译器。有很多LaTeX的发行版,我们这里可以安装使用MikTeX。可前往MikTeX官网 http://miktex.org/ 上下载对应的版本。安装完后应当进入Options->Configure TeXStudio->Commands来检查MikTeX路径是否正确
- 没有错误,但是无法生成文档。
这个可能是因为安装了其他LaTeX发行版,比如CTEX整合包的缘故,卸载该整合包,重新安装MikTeX即可。
Step 1. 使用LaTeX做Routine Work
Hello, World
新建文档,并输入1
2
3
4\documentclass{article} % meta info of the document
\begin{document}
Hello, World
\end{document}生成文档,预览
带格式的文本
新建文档,并输入1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18\documentclass{article}
\begin{document}
\noindent % no indent at the head of this paragraph
\textbf{Bold}
\newline % use this command to start a new line
\textit{Italic}
\\ % another way to start a new line
\underline{Underline}
\begin{flushleft}
Left
\end{flushleft}
\begin{center}
Middle
\end{center}
\begin{flushright}
Right
\end{flushright}
\end{document}生成文档,预览

其中:
\noindent取消段首缩进
\textbf{your_text}加粗your_text
\textit{your_text}斜体的your_text
\underline{your_text}带有下划线的your_text
\newline和\\是换行指令
\begin{command}和\end{command}之间是command的scope,其中flushleft,center,flushright表示靠左、居中和靠右对齐加入数学公式的文本
数学公式和普通文本的格式是不同的,应当使用$和$,\(和\),\begin{math}和\end{math}将数学公式包起来,如1
2
3
4
5
6
7
8
9
10\documentclass{article}
\begin{document}
$a_{1}+b_{1} = c_{1}$
\\
\( a^{2} + b^{2} = c^{2} \)
\\
\begin{math}
\frac{1}{2} + \sqrt{3} = 0
\end{math}
\end{document}特别地,使用
\[和\]或者\begin{displaymath}和\end{displaymath}能够另起一行显示公式,试比较1
2
3
4
5
6
7
8
9
10
11
12\documentclass{article}
\begin{document}
\noindent
the equlation
\[ 1+2+3+4 = 7 \]
is not established
the equlation
\( 1+2+3+4 = 7 \)
is true
\end{document}对于多个方程我们可以使用
\begin{equation}和\end{equation}来标记,并且使用\label{name}来标记,使用\ref{name}来引用。1
2
3
4
5
6
7
8
9
10
11
12
13
14\documentclass{article}
\begin{document}
\noindent
\begin{equation}
\label{eq:eps}
\epsilon > 0 % our formula
\end{equation}
\begin{equation}
\label{eq2:eps}
\delta < 0
\end{equation}
From (\ref{eq2:eps}), we can ...
\end{document}特殊字符的输入
LaTeX中有一些字符是不能“正常”输入的。- 除反斜杠之外的特殊字符,
#、$、%、^、&、_、{、}、~,可在前面直接加反斜杠,如\#便可显示# - 反斜杠(stroke):可使用
$\backslash$生成。 - 空格:使用
\,强行插入多个空格,注意一般英文文本需要两个\,才能达到理想的单词间距。其他插入空格的方式还有~、\;等 - 日期:可使用
\today生成。 - 引号:用
产生左双引号,用`''`产生右双引号。用``产生左单引号,用‘产生右单引号。当单引号与双引号相邻时,在两者中间插入空格,`。 - 取反号和波浪号:用
\~{}生成取反号(位置靠上),用$\sim$生成波浪号(位置竖直居中) - 角度°:角度是一个上标的圆圈,圆圈用
\circ生成,于是10度角就是$10^{\circ}$ - 比较符号:大于等于号可以使用
\geq、\textgreater等符号来表示。这里注意,不能以为等号是\eq,这样会报Undefined control sequence错误,等号就是=。
- 除反斜杠之外的特殊字符,
Step 2. 支持中文
缺少ctex库的情况:
- 运行 C:\Program Files (x86)\MiKTeX 2.9\miktex\bin\mpm.exe
- 设置Repository,这里建议选择第一个中科大的资源站,如果不幸40X或者50X的话可以选择翻墙去比如华盛顿大学的(翻墙的话需要配置Connection Settings)镜像站。

- 选择安装ctex

安装过程是这样的(注意进度条结束之后可能还有一个解压过程,不要点Cancel,等安装完毕,Cancel会变成Close)
- 按照以上方法安装 l3kernel, l3packages, ms, ulem, zhnumber, (cjk, cjkpunct)
(PS 亦可通过ftp://mirrors.ustc.edu.cn/CTAN/systems/win32/miktex/tm/packages/ 直接下载lmza文件安装) - 测试
1
2
3
4
5
6
7\documentclass{article}
\usepackage{ctex}
\begin{document}
\begin{CJK}{UTF8}{gkai}
蛤蛤蛤蛤蛤蛤
\end{CJK}
\end{document}

Step 3. 论文编辑的常用元素
0. 一些额外需要注意的配置
需要补充安装amsmath,listings,mptopdf几个包。这几个包的安装方法都可以参照Step2中中文支持包一样安装。-
希腊字母
1
2
3\alpha α; \beta β; \gamma γ; \delta δ; \epsilon ε; \zeta ζ; \eta η; \theta θ; \iota t;
\kappa κ; \lambda λ; \mu μ; \xi ξ:\nu ν; \o o; \pi π; \rho ρ; \sigma σ; \tau τ; \upsilon υ;
\phi Φ; \chi Χ; \psi Ψ; \omega ω将首字母大写可以得到大写的希腊字母
空格
在这里提过,可以用\,来生成一个小空格,此外数学公式中还可以用\quad和\qquad生成大小不等的空格。
一般来说,可以使用\来得到一个空格,这个空格比较小,用于词语词之间的分隔;用\@得到一个较大的句子之间的空格,用~得到一个不会在此处换行的空格。
此外,用来在一行中并列排放两个数学变量,用\quad也是一个不错的选择。其实对于空格,有以下的一些比例:\quad 即\hspace{1em},一个英文字符**M**的宽度 \qquad 即\hspace{2em},两个英文字符**M**的宽度 \; 5/18个英文字符的宽度 \: 4/18个英文字符的宽度 \, 3/18个英文字符的宽度 \! -3/18个英文字符的宽度 \hspace{长度} 产生指定宽度 \phantom{文本} 产生指定文本的宽度插入普通文本
在这里数学符号
对于任意的:\forall
存在:\exists
根号:\sqrt[n]表示n次方根,其中平方根可以省略[n]
括号:使用\big(\Big(bigg(Bigg(生成不同大小的左(括号
省略号:ldots(位置靠下)和cdots(位置居中)上标和下标
上标使用^来,下标采用_。特别地,当要将一个式子(而不是字母)作为上标,需要将这个式子整体括起来,如a^{x+y}
可以同时指定上标和下标,如a^{2}_{i}
特殊的上标,如导数符号,使用'获得。例如对f求导,应当输入f'而不是f^{'}
此外,在平均数和估计中常用的hat和bar,可以写作\hat{x},\bar{x}修饰符
向量:\vec a,\overrightarrow{AB}大的数学符号
如sigma,limit之类的数学符号在LaTeX中是相对容易输入的,选择对应的命令,按照上下标的输入方式输入即可。1
2
3
4
5
6
7
8
9
10
11
12
13
14\documentclass{article}
\begin{document}
\noindent
\begin{equation}
\label{eq:eps}
\epsilon \textrm{ simple text} > 0 % our formula
\end{equation}
\begin{equation}
\label{eq1:eps}
\lim_{n \to \infty}
\sum_{k=1}^n k
= \infty
\end{equation}
\end{document}数学公式
使用双斜杠换行1
2
3
4
5
6
7
8
9\documentclass{article}
\begin{document}
\noindent
\begin{equation}
\alpha_1 f_c b x = f_y A_s \\
M_u = f_y A_s (h_0 - \frac{x}{2}) \\
M_u = \alpha_1 f_c b x (h_0 - \frac{x}{2}) \\
\end{equation}
\end{document}方程组的情况:
-
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16\documentclass{article}
\usepackage{CJKutf8}
\usepackage{amsmath}
\usepackage{listings}
\usepackage{graphicx}
\begin{document}
\noindent
\begin{equation}
\begin{bmatrix}
-1& 1& 1& 1& -1& \ldots & -1 \\
-1&1&1&-1&-1& \ddots & -1 \\
\vdots& \vdots& \vdots& \vdots& \vdots& \vdots& \vdots& \\
1& 1& 1&-1&-1& \ldots & 1 \\
\end{bmatrix}
\end{equation}
\end{document}这里要注意几点:
\begin{bmatrix}标记的,不过需要在数学编辑的环境下哦。- 第一,
\usepackage{amsmath}这个包是必备的,如果没有是无法生成文档的。 - 第二,
&区分矩阵中每一行的元素,\\区分矩阵中的每一行。 - 第三,
&后面的空格不是必须的,但是有了这个空格,源码会显得比较明朗,也易于修改。 - 第四,
\ldots,\ddots,\vdots分别表示横过来的,斜过来的,竖过来的省略号。
- 第一,
-
首先先生成一个最简单的表格
1
2
3
4
5
6
7
8
9
10
11
12\documentclass{article}
\usepackage{multirow}
\begin{document}
\noindent
\begin{tabular}{|l|c|r|}
\hline
1 & 2 & 3 \\
4 & 5 & 6 \\
7 & 8 & 9 \\
\hline
\end{tabular}
\end{document}可以看出表格和矩阵时差不多的,
&区分矩阵中每一行的元素,\\区分矩阵中的每一行。额外有几点的区别,补充说明如下:- 我们使用
\begin{tabular}和\end{tabular}来标记一个表格(注意,是tabular不是table哦)。 - 后面的
{|l|c|r|}抽象地表示了一个表格的一行。其中|表示竖向的表格线,从而形成一行表格,当然也可以用||,这样表格线就是双层的啦。里面的l、c、r分别表示在这个格子里面中的文字是靠左,居中还是靠右对齐。特别地,当表格有很多行的时候写起来会比较麻烦,这时候可以采用重复指令*{n}{repeat},其中*{n}{repeat}表示重复repeat n次,模板如下:*{3}{|c}|表示一个三列的表格且都是居中。 \hline表示横向的表格线。
- 我们使用
下面给表格加上一个标题:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16\documentclass{article}
\usepackage{multirow}
\begin{document}
\noindent
\begin{table}
\caption{My first table}
\centering
\begin{tabular}{|l|c|r|}
\hline
1 & 2 & 3\\
4 & 5 & 6 \\
7 & 8 & 9 \\
\hline
\end{tabular}
\end{table}
\end{document}
可以看到,在\begin{tabular}外面又套了一层\begin{table},这两层是不相同的,我们需要在\begin{table}里面,\begin{tabular}外面用\caption{My first table}指定标题为“My first table”,而下面的\centering指令是让表格居中。
其实我们可以发现\begin{tabular}表示一个表格实体的开始,而\begin{table}表示一个表格连同标题至脚注的开始。在Word中常常用到“合并单元格”和拆分单元格指令,在LaTeX中可以通过
\multirow和\multicolumn来实现。这里\usepackage{multirow}是必备的。
先看一个例子:现有一个4x4的表:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17\documentclass{article}
\usepackage{multirow}
\usepackage{ctex}
\begin{document}
\begin{CJK}{UTF8}{gkai}
\noindent
\renewcommand{\multirowsetup}{\centering}
\begin{tabular}{|l|l|l|l|}
\hline
1行1列 & 1行2列 & 1行3列 & 1行4列 \\
2行1列 & 2行2列 & 2行3列 & 2行4列 \\
3行1列 & 3行2列 & 3行3列 & 3行4列 \\
4行1列 & 4行2列 & 4行3列 & 4行4列 \\
\hline
\end{tabular}
\end{CJK}
\end{document}
下面我们合并第一列和第三列。1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17\documentclass{article}
\usepackage{multirow}
\usepackage{ctex}
\begin{document}
\begin{CJK}{UTF8}{gkai}
\noindent
\renewcommand{\multirowsetup}{\centering}
\begin{tabular}{|l|l|l|l|}
\hline
\multirow{4}{2cm}{第1列} & 1行2列 & \multirow{4}{2cm}{第3列} & 1行4列 \\
& 2行2列 & & 2行4列 \\
& 3行2列 & & 3行4列 \\
& 4行2列 & & 4行4列 \\
\hline
\end{tabular}
\end{CJK}
\end{document}
对比代码发现,合并行单元格,我们只要在被合并的单元格的起始单元格调用\multirow命令,然后在被这个大单元格占据的其他地方使用空格代替原来的字符就行了。
这里说明一下\multirow命令的参数,第一个参数,这里是4表示向下合并多少行的单元格,第二个参数,这里是2cm一般取2cm或者*就可以,第三个参数,就是这个大单元格里面的内容了,你可以在里面嵌入其他指令,如textbf用来加粗等。
此外对于合并列,有同样的\multicolumn指令,注意这里第二个参数变成了{c|}这样,用来说明这个大单元格内文本的对齐方式。不过这里需要特别注意的一点就是,在同一行中,我们不需要给被\multicolumn吃掉的单元格占位置了。1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17\documentclass{article}
\usepackage{multirow}
\usepackage{ctex}
\begin{document}
\begin{CJK}{UTF8}{gkai}
\noindent
\renewcommand{\multirowsetup}{\centering}
\begin{tabular}{|l|l|l|l|}
\hline
1行1列 & 1行2列 & \multicolumn{2}{|c|}{1行34列} \\ \cline{1-4}
2行1列 & 2行2列 & 2行3列 & 2行4列 \\
3行1列 & 3行2列 & 3行3列 & 3行4列 \\
4行1列 & 4行2列 & 4行3列 & 4行4列 \\
\hline
\end{tabular}
\end{CJK}
\end{document}
注意这里第10行的\cline{1-4},试着将它去掉,我们可以发现\multicolumn部分失去了下面的表格构造线。这里\cline{1-4}表示在第1列到第4列画上表格构造线。
如果要实现合并多行多列的单元格可以嵌套使用指令\multirow,\multicolumn。1
2
3
4
5
6
7
8
9
10
11
12
13
14% 此例修改自知乎专栏,作者李阿玲。
% http://zhuanlan.zhihu.com/LaTeX/19749566
\documentclass{article}
\usepackage{multirow}
\begin{document}
\noindent
\begin{tabular}{|ccc|}
\hline
1 & 2 & 3 \\
4 & \multicolumn{2}{c|} { \multirow{2}{*}{{?}} } \\
7 & & \\
\hline
\end{tabular}
\end{document}
特别地,\renewcommand用来重定义一个指令,对于\renewcommand{\multirowsetup}{\centering}来说,就是把系统中已有的\multirowsetup重新定义成了使用\centering命令,从而达到强制multirow中内容居中居中的效果。当然还有newcommand用来定义一个之前不存在的命令,如同C++里面的#define一样。斜线表头。为了能够使用斜线表头,需要
\usepackage{diagbox},\usepackage{pict2e},\usepackage{fp}包。1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17% 此例修改自知乎专栏,作者李阿玲。
% http://zhuanlan.zhihu.com/LaTeX/19749566
\documentclass{article}
\usepackage{multirow}
\usepackage{booktabs}
\usepackage{diagbox}
\begin{document}
\noindent
\begin{tabular}{|l|ccc|}
\hline
\diagbox{Time}{Room}{Day} & Mon & Tue & Wed \\
\hline
Morning & used & used & \\
Afternoon & & used & used \\
\hline
\end{tabular}
\end{document}
注意第11行
\diagbox{Time}{Room}{Day}表示顺时针的三个Time,Room,Day。

- 三线表。对于英文论文来说,表格尽量 使用三线表格式。需要
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16% 此例修改自知乎专栏,作者李阿玲。
% http://zhuanlan.zhihu.com/LaTeX/19749566
\documentclass{article}
\usepackage{multirow}
\usepackage{booktabs}
\begin{document}
\noindent
\begin{tabular}{ccc}
\toprule
2&9&4\\
\midrule
7&5&3\\
6&1&8\\
\bottomrule
\end{tabular}
\end{document}

-
有序列表enumerate:
1
2
3
4
5
6
7
8
9\documentclass{article}
\begin{document}
\noindent
\begin{enumerate}
\item C
\item Python
\item Haskell
\end{enumerate}
\end{document}无序列表enumerate:
1
2
3
4
5
6
7
8
9\documentclass{article}
\begin{document}
\noindent
\begin{itemize}
\item CSharp
\item Javascript
\item Rust
\end{itemize}
\end{document}带小标题的列表description:
1
2
3
4
5
6
7
8
9\documentclass{article}
\begin{document}
\noindent
\begin{description}
\item[C++] Leaking basin
\item[PHP] Best language in the world
\item[Perl] WTF
\end{description}
\end{document}
-
1
2
3
4
5
6
7
8
9
10
11\documentclass{article}
\usepackage{CJKutf8}
\usepackage{amsmath}
\usepackage{listings}
\begin{document}
\noindent
\begin{lstlisting}[language=python]
#coding:utf8
import numpy as np
\end{lstlisting}
\end{document}这里同样注意
\usepackage{listings}包不能丢掉,其中language表示里面显示的是什么语言。
Step 4. 段落,段落格式和目录
分段
LaTeX对分段有着以下几个明确的指令1
2
3
4
5
6
7\section{...}
\subsection{...}
\subsubsection{...}
\paragraph{...}
\subparagraph{...}
\part{...}
\chapter{...}注意:chapter仅限于report和book类(点击查看详细说明)
前五个命令表示从大到小的5个五级标题,其中含paragraph的一般为段落,前面没有标号,而且需要有实际的内容,不然这个paragraph就不会被显示(试着将含有remove me的行注释掉,注意观察编译结果),编译:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15\documentclass{article}
\usepackage{ctex}
\begin{document}
\begin{CJK}{UTF8}{gkai}
\section{section}
\subsection{subsection}
\subsubsection{subsubsection}
\paragraph{paragraph1}
there's some subparagraph
\subparagraph{subparagraph1}
\subparagraph{subparagraph2}
\paragraph{paragraph2} % remove me
there's no more subparagraph % remove me
\end{CJK}
\end{document}
此外,还有一种\section{short_title}{long_title}的写法,在中间的short_title我们指定一个简短的标题名,用来后面生成目录。
下面是part指令,类似于section,不过相比section,part是不带编号的,而且\part{}自动生成类似Part I这样的标题,不需要写成\part{Part I},所以一般part指令都是用在比较独立的地方,比如用在chapter和section中间。
这边注意一点:请不要用section或者paragraph指令去做有序列表或者无序列表,点此查看专门的方案1
2
3
4
5
6
7
8
9
10
11\documentclass{article}
\usepackage{ctex}
\begin{document}
\begin{CJK}{UTF8}{gkai}
\section{section1}
\part{}
\part{}
\part{}
\section{section2}
\end{CJK}
\end{document}
通过之前的几个例子,我们发现section系是不带编号的,paragraph和part是带编号的。事实上section也可以不带编号,paragraph也可以带编号。事实上这个是可以调整的。
运行一下代码,将\setcounter的最后一个参数从1一直调到5,逐次编译,比较每次的不同。1
2
3
4
5
6
7
8
9
10
11
12
13\documentclass{article}
\usepackage{ctex}
\begin{document}
\begin{CJK}{UTF8}{gkai}
\setcounter{secnumdepth}{5} % change this from 1 to 5
%控制显示4层编号
\section{A}
\subsection{B}
\subsubsection{C}
\paragraph{D} D
\subparagraph{E} E
\end{CJK}
\end{document}对于
article文档类来说,\setcounter默认的是3,也就是默认section系的有编号,parag系的没有编号。
事实上,如果我们仅仅只是想去掉一级section的编号的话,可以使用\section*{...}在\section和实际内容之间加上一个*就可以实现了。目录和标题
先使用\title{},\author{}和可选的\data{}为文章设置标题。
再使用\maketitle显示标题。
Step 5. 图片
Step 6. 页面设置
Step 7. 模板
Step inf. 额外说明
文档类
文档类一般包括以下几个1
2
3
4
5article 最常用的
minimal 最基本的文档类,一般仅用来查错
report 较长的报告和论文
book 书籍
slides 幻灯片使用
\documentclass{...}定义。本文中大多数都是article类型
