TeX排版概览
TeX是Knuth, Donald Ervin(高德纳)为排版《计算机程序设计的艺术》而设计和实现的一种排版系统,用于排版书籍——特别是包含很多数学公式的书籍。TeX有着优秀的出版级排版算法和强大的可扩展性,熟练的用户可以轻自动化各种编号、交叉引用、目录、索引、注释等等,但也不时为迷惑用户。
用法
在类unix中一般可安装texlive。
现在有几个TeX引擎,如原始的tex、支持Unicode的xetex,对于latex则常用latex、pdflatex或xelatex,通常以tex文件名(可不加后缀)为参数运行同名命令即可,由于运行一次只进行一趟处理,在涉及目录、参考文献等等时需运行两遍才能得到正确结果。
基本TeX
基本的TeX语言在Knuth的《The TeXBook》中介绍。
词法
TeX中通常每个字符视为一个标记,只有在碰到\时:
- 若下一字符为字母,标记由
\和紧接的尽可能多个字母组成,后面的空格被忽略 - 否则,标记由
\和紧接的一个字符组成
这些控制序列是有特殊含义的命令。另外,从%开始到行末被视为注释。多个相继的空格视为一个。
TeX提供了约300个基本命令,但由于它们大多过于底层,实际上常用的是一组基于基本命令的宏。现在最流行的当数latex。
宏包
TeX有很多宏包,见CTAN,一般都有详细的文档。常见的tex发行版都有包管理器,如texlive有tlmgr,可以安装绝大多数流行的宏包。另外,也可用系统的包管理器。
LaTeX
LaTeX 是一个最初由Leslie Lamport 编写的宏集,它使用一个预先定义好的专业版面,目前有主导地位。关于LaTeX,lshort是通常随LaTeX发布的一个教程。以下摘录LaTeX的部分常用功能:
文件结构
基本的LaTeX文件形如:
\documentclass[用逗号分隔的选项列表]{文类}
%导言
\begin{document}
%内容
\end{document}
其中\documentclass命令中,文类可选article、report、book、letter、slides等等,选项则有:
- 字体大小如10pt(默认)、11pt、12pt
- 纸张大小如a4paper、a5paper、b5paper、executivepaper、legalpaper、letterpaper
- 是否标记出界draft、final
- 行间公式左对齐fleqn(默认居中)
- 纸张方向landscape(默认纵向)
- 公式编号靠左leqno(默认右)
- 参考文献格式如openbib
- 有否封面titlepage, notitlepage
- 分栏如onecolumn(默认)、twocolumn
- 是否双面oneside(非book的文类默认)、twoside
- 章是否从右页开始openright(book默认)、openany
在导言区中常导入宏包如:
\usepackage[用逗号分隔的选项列表]{用逗号分隔的包列表}
\documentclass命令未被文类识别的选项也会传到这些宏包。
字体
字体设置命令有两类:
- 局部字体设置命令有一个参数,设置显示参数的字体
- 全局字体设置命令没有参数,设置从当前位置有效到其它全局字体设置命令或分组结束,效果可以累加,如
\sffamily\bfseries可得直立粗体。(对应也有同名环境)
| 局部字体设置命令 | 全局字体设置命令 | 效果 |
|---|---|---|
| \textrm | \rmfamily | 罗马体 |
| \textit | \itshape | 斜体 |
| \emph | 交换罗马体和斜体 | |
| \textmd | \mdseries | 中等权值(默认) |
| \textbf | \bfseries | 粗体 |
| \textup | \upshape | 直立(默认) |
| \textsl | \slshape | 倾侧 |
| \textsf | \sffamily | 无衬线 |
| \textsc | \scshape | 小大写 |
| \texttt | \ttfamily | 等宽 |
| \textnormal | \normalfont | 主文档字体 |
| \mathrm | 用于数学模式的罗马体 | |
| \mathbf | 用于数学模式的粗体 | |
| \mathsf | 用于数学模式的无衬线体 | |
| \mathtt | 用于数学模式的等宽 | |
| \mathit | 用于数学模式的斜体 | |
| \mathnormal | 用于数学模式的正常字体 | |
| \mathcal | 用于数学模式的花写 |
另外有对应的不可累加全局字体设置命令:\bf、\cal、\em、\it、\rm、\sc、\sf、\sl、\tt。
至于全局字体大小设置命令,有
| 命令 | 10pt | 11pt | 12pt |
|---|---|---|---|
| \tiny | 5 | 6 | 6 |
| \scriptsize | 7 | 8 | 8 |
| \footnotesize | 8 | 9 | 10 |
| \small | 9 | 10 | 10.95 |
| \normalsize | 10 | 10.95 | 12 |
| \large | 12 | 12 | 14.4 |
| \Large | 14.4 | 14.4 | 17.28 |
| \LARGE | 17.28 | 17.28 | 20.74 |
| \huge | 20.74 | 20.74 | 24.88 |
| \Huge | 24.88 | 24.88 | 24.88 |
页面布局
| 命令 | 用途 |
|---|---|
| \onecolumn | 开始单栏排版的新页 |
| \twocolumn | 开始双栏排版的新页 |
| \flushbottom | 让所有文本页一样高(双栏模式默认) |
| \raggedbottom | 让各文本页分别用其自然高度 |
| \cleardoublepage | 打印所有浮动体并开新页(必要时在右) |
| \clearpage | 打印所有浮动体并开新页(必要时在右) |
| \newpage | 开新页 |
| \enlargethispage{size} | 加大当前页的页高 |
| \enlargethispage*{size} | 加大当前页的页高(尽可能多放东西) |
| \pagebreak[priority] | 强制在当前位置换页,有从1到4的优先级时为建议 |
| \nopagebreak[priority] | 禁止在当前位置换页,有从1到4的优先级时为建议 |
| \pagenumbering{style} | 页码格式,如arabic、roman、Roman、alph、Alph |
| \pagestyle{style} | 本页起页眉和页脚样式,如plain(仅页码)、empty(空)、headings(加上标题) |
| \markboth{left}{right} | 设置标题 |
| \markright{right} | 设置右标题(左标题不变) |
| \thispagestyle{style} | 本页页眉和页脚样式,如plain(仅页码)、empty(空)、headings(加上标题) |
排版参数包括:
| 参数 | 含义 | 默认 |
|---|---|---|
| \columnsep | 栏间隔 | 35pt |
| \columnseprule | 栏分隔线宽度 | 0pt |
| \columnwidth | 栏宽 | |
| \dbltopfraction | 双栏页上方可被浮动体占的最大比例 | .7 |
| \dblfloatpagefraction | 双栏页上方可被浮动体占的最小比例.5 | |
| \dblfloatsep | 双栏浮动页中浮动体间隔12pt plus2pt minus2pt或14pt plus2pt minus4pt(若12pt) | |
| \dbltextfloatsep | 浮动体与正文的上下间距 | 20pt plus2pt minus4pt |
| \headheight | 页眉标题的高度 | 30pt(除book) |
| \headsep | 页眉标题底与正文顶的距离 | 25pt(除book) |
| \footskip | 正文最后一行基线与脚注基线间的距离 | 30pt(除book) |
| \linewidth | 当前行长度 | |
| \textheight | 正常页体高度 | 43\baselineskip(10pt非book)、41\baselineskip(10pt book)、38\baselineskip(11pt)、36\baselineskip(12pt) |
| \textwidth | 页的宽度 | 对于article或report,345pt、360pt、390pt;对于book,4.5in、5in、11pt |
| \topmargin | 页眉标题顶与TEX页(去掉页边)顶的距离 | (\paperheight − 2in − \headheight − \headsep −\textheight − \footskip )/2 |
| \topskip | 页顶与首行基线的最小距离10pt、11pt、12pt |
章节结构
\part、\chapter(只用于report和book)、\section、\subsection、\subsubsection、\paragraph、\subparagraph命令用于组织从大到小的结构,用法如以下之一:
\chapter[目录中标题]{标题}
\chapter*{标题}
其中[目录中标题]是可选的。两种写法区别在于后者不会出现在目录。
另外,\appendix可标记附录开始。
每段由相继的空行(注释都没有)分隔,垂直间隔由\parskip决定,默认0pt plus1pt。\indent生成宽度为\parindent水平空白,\parindent默认为15pt、17pt或1.5em ,双栏则1em。相反段首的\noindent将防止缩进。
段中的文本会自动断行,有时会自动断词以尽可能美观,但也可人工干预:
| 命令 | 用途 |
|---|---|
| \[morespace] | 换行,可指定额外的垂直空白 |
| \*[morespace] | 换行并换页,可指定额外的垂直空白 |
| \obeycr | 使后面按输入的换行符换行 |
| \restorecr | 恢复正常 |
| \newline | 换行且不拉伸前面文本 |
| \- | 指定可行的断词位置 |
| \fussy | 以有时出界为代价换取词间不要太多空白(默认) |
| \sloppy | 与\fussy相反 |
| \hyphenation{ap-pen-dix col-umns data-base data-bases} | 指定一些单词的可行断词点 |
| \linebreak[priority] | 强制在当前位置换行,有从0到4的优先级时为建议 |
| \nolinebreak[priority] | 禁止在当前位置换行,有从0到4的优先级时为建议 |
数学公式
数学符号
| 命令 | 符号 |
|---|---|
| \| | | |
| \aleph | $\aleph$ |
| \alpha | $\alpha$ |
| \amalg | $\amalg$ |
| \angle | $\angle$ |
| \approx | $\approx$ |
| \ast | $\ast$ |
| \asymp | $\asymp$ |
| \backslash | $\backslash$ |
| \beta | $\beta$ |
| \bigcap | $\bigcap$ |
| \bigcirc | $\bigcirc$ |
| \bigcup | $\bigcup$ |
| \bigodot | $\bigodot$ |
| \bigoplus | $\bigoplus$ |
| \bigotimes | $\bigotimes$ |
| \bigtriangledown | $\bigtriangledown$ |
| \bigtriangleup | $\bigtriangleup$ |
| \bigsqcup | $\bigsqcup$ |
| \biguplus | $\biguplus$ |
| \bigcap | $\bigcap$ |
| \bigwedge | $\bigwedge$ |
| \bot | $\bot$ |
| \bowtie | $\bowtie$ |
| \bullet | $\bullet$ |
| \cap | $\cap$ |
| \cdot | $\cdot$ |
| \chi | $\chi$ |
| \circ | $\circ$ |
| \clubsuit | $\clubsuit$ |
| \cong | $\cong$ |
| \coprod | $\coprod$ |
| \cup | $\cup$ |
| \dagger | $\dagger$ |
| \dashv | $\dashv$ |
| \ddagger | $\ddagger$ |
| \Delta | $\Delta$ |
| \delta | $\delta$ |
| \Diamond | $\Diamond$ |
| \diamond | $\diamond$ |
| \diamondsuit | $\diamondsuit$ |
| \div | $\div$ |
| \doteq | $\doteq$ |
| \downarrow | $\downarrow$ |
| \Downarrow | $\Downarrow$ |
| \ell | $\ell$ |
| \emptyset | $\emptyset$ |
| \epsilon | $\epsilon$ |
| \equiv | $\equiv$ |
| \eta | $\eta$ |
| \exists | $\exists$ |
| \flat | $\flat$ |
| \forall | $\forall$ |
| \frown | $\frown$ |
| \Gamma | $\Gamma$ |
| \gamma | $\gamma$ |
| \ge | $\ge$ |
| \geq | $\geq$ |
| \gets | $\gets$ |
| \gg | $\gg$ |
| \hbar | $\hbar$ |
| \heartsuit | $\heartsuit$ |
| \hookleftarrow | $\hookleftarrow$ |
| \hookrightarrow | $\hookrightarrow$ |
| \iff | $\iff$ |
| \Im | $\Im$ |
| \in | $\in$ |
| \infty | $\infty$ |
| \int | $\int$ |
| \iota | $\iota$ |
| \Join | $\Join$ |
| \kappa | $\kappa$ |
| \Lambda | $\Lambda$ |
| \lambda | $\lambda$ |
| \land | $\land$ |
| \langle | $\langle$ |
| \lbrace | $\lbrace$ |
| \lbrack | $\lbrack$ |
| \lceil | $\lceil$ |
| \le | $\le$ |
| \leadsto | $\leadsto$ |
| \Leftarrow | $\Leftarrow$ |
| \leftarrow | $\leftarrow$ |
| \leftharpoondown | $\leftharpoondown$ |
| \leftharpoonup | $\leftharpoonup$ |
| \Leftrightarrow | $\Leftrightarrow$ |
| \leftrightarrow | $\leftrightarrow$ |
| \leq | $\leq$ |
| \lfloor | $\lfloor$ |
| \lhd | $\lhd$ |
| \ll | $\ll$ |
| \lnot | $\lnot$ |
| \longleftarrow | $\longleftarrow$ |
| \longleftrightarrow | $\longleftrightarrow$ |
| \longmapsto | $\longmapsto$ |
| \longrightarrow | $\longrightarrow$ |
| \lor | $\lor$ |
| \mapsto | $\mapsto$ |
| \mho | $\mho$ |
| \mid | $\mid$ |
| \models | $\models$ |
| \mp | $\mp$ |
| \mu | $\mu$ |
| \nabla | $\nabla$ |
| \natural | $\natural$ |
| \ne | $\ne$ |
| \nearrow | $\nearrow$ |
| \neg | $\neg$ |
| \neq | $\neq$ |
| \ni | $\ni$ |
| \not | $\not$ |
| \notin | $\notin$ |
| \nu | $\nu$ |
| \nwarrow | $\nwarrow$ |
| \odot | $\odot$ |
| \oint | $\oint$ |
| \Omega | $\Omega$ |
| \omega | $\omega$ |
| \ominus | $\ominus$ |
| \oplus | $\oplus$ |
| \oslash | $\oslash$ |
| \otimes | $\otimes$ |
| \owns | $\owns$ |
| \parallel | $\parallel$ |
| \partial | $\partial$ |
| \perp | $\perp$ |
| \phi | $\phi$ |
| \Pi | $\Pi$ |
| \pi | $\pi$ |
| \pm | $\pm$ |
| \prec | $\prec$ |
| \preceq | $\preceq$ |
| \prime | $\prime$ |
| \prod | $\prod$ |
| \propto | $\propto$ |
| \Psi | $\Psi$ |
| \psi | $\psi$ |
| \rangle | $\rangle$ |
| \rbrace | $\rbrace$ |
| \rbrack | $\rbrack$ |
| \rceil | $\rceil$ |
| \Re | $\Re$ |
| \rfloor | $\rfloor$ |
| \rhd | $\rhd$ |
| \rho | $\rho$ |
| \Rightarrow | $\Rightarrow$ |
| \rightarrow | $\rightarrow$ |
| \rightharpoondown | $\rightharpoondown$ |
| \rightharpoonup | $\rightharpoonup$ |
| \rightleftharpoons | $\rightleftharpoons$ |
| \searrow | $\searrow$ |
| \setminus | $\setminus$ |
| \sharp | $\sharp$ |
| \Sigma | $\Sigma$ |
| \sigma | $\sigma$ |
| \sim | $\sim$ |
| \simeq | $\simeq$ |
| \smallint | $\smallint$ |
| \smile | $\smile$ |
| \spadesuit | $\spadesuit$ |
| \sqcap | $\sqcap$ |
| \sqcup | $\sqcup$ |
| \sqsubset | $\sqsubset$ |
| \sqsubseteq | $\sqsubseteq$ |
| \sqsupset | $\sqsupset$ |
| \sqsupseteq | $\sqsupseteq$ |
| \star | $\star$ |
| \subset | $\subset$ |
| \subseteq | $\subseteq$ |
| \succ | $\succ$ |
| \succeq | $\succeq$ |
| \sum | $\sum$ |
| \supset | $\supset$ |
| \supseteq | $\supseteq$ |
| \surd | $\surd$ |
| \swarrow | $\swarrow$ |
| \tau | $\tau$ |
| \theta | $\theta$ |
| \times | $\times$ |
| \to | $\to$ |
| \top | $\top$ |
| \triangle | $\triangle$ |
| \triangleleft | $\triangleleft$ |
| \triangleright | $\triangleright$ |
| \unlhd | $\unlhd$ |
| \unrhd | $\unrhd$ |
| \Uparrow | $\Uparrow$ |
| \uparrow | $\uparrow$ |
| \Updownarrow | $\Updownarrow$ |
| \updownarrow | $\updownarrow$ |
| \uplus | $\uplus$ |
| \Upsilon | $\Upsilon$ |
| \upsilon | $\upsilon$ |
| \varepsilon | $\varepsilon$ |
| \varphi | $\varphi$ |
| \varpi | $\varpi$ |
| \varrho | $\varrho$ |
| \varsigma | $\varsigma$ |
| \vartheta | $\vartheta$ |
| \vdash | $\vdash$ |
| \vee | $\vee$ |
| \Vert | $\Vert$ |
| \vert | $\vert$ |
| \wedge | $\wedge$ |
| \wp | $\wp$ |
| \wr | $\wr$ |
| \Xi | $\Xi$ |
| \xi | $\xi$ |
| \zeta | $\zeta$ |
罗马体符号
| 命令 | 结果 |
|---|---|
| \arccos | $\arccos$ |
| \arcsin | $\arcsin$ |
| \arctan | $\arctan$ |
| \arg | $\arg$ |
| \bmod | $\bmod$ |
| \cos | $\cos$ |
| \cosh | $\cosh$ |
| \cot | $\cot$ |
| \coth | $\coth$ |
| \csc | $\csc$ |
| \deg | $\deg$ |
| \det | $\det$ |
| \dim | $\dim$ |
| \exp | $\exp$ |
| \gcd | $\gcd$ |
| \hom | $\hom$ |
| \inf | $\inf$ |
| \ker | $\ker$ |
| \lg | $\lg$ |
| \lim | $\lim$ |
| \liminf | $\liminf$ |
| \limsup | $\limsup$ |
| \ln | $\ln$ |
| \log | $\log$ |
| \max | $\max$ |
| \min | $\min$ |
| \pmod{n} | $\pmod{n}$ |
| \Pr | $\Pr$ |
| \sec | $\sec$ |
| \sin | $\sin$ |
| \sinh | $\sinh$ |
| \sup | $\sup$ |
| \tan | $\tan$ |
| \tanh | $\tanh$ |
帽子
| 命令 | 效果 |
|---|---|
| \acute{x} | $\acute{x}$ |
| \bar{x} | $\bar{x}$ |
| \breve{x} | $\breve{x}$ |
| \check{x} | $\check{x}$ |
| \ddot{x} | $\ddot{x}$ |
| \dot{x} | $\dot{x}$ |
| \grave{x} | $\grave{x}$ |
| \hat{x} | $\hat{x}$ |
| \imath | $\imath$ |
| \jmath | $\jmath$ |
| \mathring{x} | $\mathring{x}$ |
| \tilde{x} | $\tilde{x}$ |
| \vec{x} | $\vec{x}$ |
| \widehat{xyz} | $\widehat{xyz}$ |
| \widetilde{xyz} | $\widetilde{xyz}$ |
空白
| 命令 | 长度 |
|---|---|
| \; | 5/18 quad |
| : | 2/9 quad |
| > | 2/9 quad |
| \, | 1/6 quad |
| ! | -1/6 quad |
杂项
^和_分别使后面一个分组为上标和下标。
| 命令 | 用途 |
|---|---|
| * | 离散乘法,容许断行 |
| \cdots | 水平省略号 |
| \ddots | 斜省略号 |
| \frac{num}{den} | 分式 |
| \left delim1 | 左括号 |
| \right delim2 | 右括号 |
| \overbrace[sup]{text} | 上花括号 |
| \overline{text} | 上划线 |
| \sqrt[root]{arg} | 方根 |
| \stackrel{text}{relation} | 把text放到relation上 |
| \underbrace[sub]{math} | 下花括号 |
| \underline{text} | 下划线 |
| \vdots | 垂直省略号 |
| \boldmath | 粗体模式 |
| \unboldmath | 正常模式 |
| \displaystyle | 行间公式风格 |
交叉引用和注记
交叉引用
| 命令 | 用途 |
|---|---|
| \label{key} | 创建一个标记key,并给予一个与环境有关的编号 |
| \pageref{key} | 引用\label{key}命令出现的页码 |
| \ref{key} | 引用标记key的编号 |
其中标记key可以为任何由字母、数字、标点符号组成的序列,区分大小写。通常用前缀如ch、sec、fig、tab、eq区分不同类型的标记。
脚注
| 命令 | 用途 |
|---|---|
| \footnote[number]{text} | 增加一个内容为text的脚注,可指定编号,只用于段的外层 |
| \footnotemark[number] | 放置额外的脚注引用 |
| \footnotetext[number]{text} | 增加一个内容为text的脚注,可指定编号,只用于段的外层 |
| 参数 | 含义 | 默认 |
|---|---|---|
| \footnoterule | 生成正文与脚注分隔线 | 0.4pt 粗、0.4\columnwidth长 |
| \footnotesep | 脚注间隔 | 6.65pt、7.7pt或8.4pt |
设置编号样式可如\renewcommand{\thefootnote}{\fnsymbol{footnote}}。
边注
\marginpar[左边注]{右边注}
用于生成边注,只指定右边注时,会放到外侧(双面)或近侧(双栏)。
| 参数 | 含义 | 默认 |
|---|---|---|
| \marginparpush | 边注间最小的垂直距离 | 7pt(对于12pt文档)或5pt(其它) |
| \marginparsep | 边注与正文的最小距离 | 11pt(对于10pt文档)或10pt(其它) |
| \marginparwidth | 边注宽度 | 90pt或83pt或68pt,双面的再加17pt,双栏模式默认48pt |
环境
环境用于给予一段文本特殊含义,其语法如:
\begin{环境名}
%内容
\end{环境名}
| 环境 | 参数 | 用途 |
|---|---|---|
| abstract | 摘要 | |
| array | {template}指定各列对齐(c、l、r的序列) | 数组,其中用\\分行,用&分列,只用于数学模式 |
| center | 居中(对应\centering全局设置命令) | |
| description | 描述列表,每项如\item[标签] 项目 |
|
| displaymath | 行间公式,相当于用$$包围或用\[与\]包围 |
|
| document | ||
| enumerate | 有序列表,每项如\item 项目 |
|
| eqnarray | 多行公式,其中用\\分行,用&分列,用\nonumber暂停对当前行编号 |
|
| eqnarray* | 与eqnarray类似但不编号 | |
| equation | 编号的行间公式 | |
| figure | [placement]其中由t(页顶)、b(页底)、h(当前位置)、p(浮动体页)、!(放松限制)组成,默认[tbp] |
用于图形的浮动体,其中可用\caption[loftitle]{text}指定标题 |
| flushleft | 左对齐(对应\raggedright全局设置命令) | |
| flushright | 右对齐(对应\raggedleft全局设置命令) | |
| itemize | 无序列表,每项如\item 项目 |
|
| list | {labeling}{spacing} |
列表,每项如\item 项目 |
| math | 行内公式,相当于用$包围或用\(与\)包围 |
|
| minipage | [position][height][inner-pos]{width} | 与parbox类似但容许用生成段落的环境和脚注 |
| picture | (width,height)(x offset,y offset) | 画图 |
| quotation | 多段引用 | |
| quote | 单段引用 | |
| tabbing | 打字机式的表格 | |
| table | [placement]默认[tbp] |
用于表格的浮动体,类似figure |
| tabular | [pos]{cols} | 表格, |
| tabular* | {width}[pos]{cols} | 表格,pos可为t或b,cols为以下的序列:l左对齐列、r右对齐列、c居中列、|列分隔线、@{每列都有的文本}、p{宽度}定宽列、*{重复次数}{cols},表格中中用\\分行,用&分列,用\multicolumn{cols}{pos}{text}生成跨列单元格(cols为列数,pos为l、c或r)、用\cline{i-j}或\hline生成行分隔线,用\vline生成单元格分隔线 |
| thebibliography | {最宽标签} | 参考文献,其中条目如\bibitem[label]{cite_key},条目可在正文用\cite[subcite]{key,...}或\nocite{key,...}引用 |
| titlepage | 标题页 | |
| verbatim | 原样输出,对应仅对下一分组有效的\verb和\verb*(后者突出空格) |
|
| verse | 韵文 |
其中,picture环境中可用以下画图命令(长度单位为\unitlength):
| 命令 | 用途 |
|---|---|
| \circle*{diameter} | 圆 |
| \circle*{diameter} | 实心圆 |
| \makebox(width,height)[position]{…} | 生成盒子,其中position在t、b、l、r中选至多两个决定对齐 |
| \framebox(width,height)[pos]{…} | 生成带边框盒子 |
| \dashbox{dlen}(rwidth,rheight)[pos]{text} | 虚线边框的盒子,每段虚线长dlen |
| \frame{text} | 框住的文本 |
| \line(xslope,yslope){length} | 线段 |
| \linethickness{dim} | 指定垂直和水平的线粗 |
| \thicklines | 垂直和水平的备选线粗 |
| \thinlines | 垂直和水平的默认线粗 |
| \multiput(x,y)(delta_x,delta_y){n}{obj} | 重复画出指定对象 |
| \oval(width,height)[portion] | 圆角矩形,portion可为t、b、r、l |
| \put(x coord,y coord){ … } | 画出指定对象 |
| \shortstack[position]{…\\…\\…} | 堆叠对象,其中position可选r、l、c |
tabbing环境中可用以下命令:
命令|用途
—|—
\\|结束一行
=|在当前位置设置制表位
>|跳到下一制表位
<|把接下来的文本放到边界左边,只用于行首
+|把后面内容右移一个制表位
-|把后面内容左移一个制表位
'|把在当前列输入的内容移到当前制表位右侧
\`|右对齐
\a|加在重音符前,如通常的\=在表格中改为\a=
\kill|设置制表位但不输出文本
\poptabs|从栈弹出各制表位
\pushtabs|把当前的各制表位入栈
\tabbingsep|Distance to left of tab stop moved by '移动的
| 参数 | 含义 | 默认值 |
|---|---|---|
| \labelitemi | 第1层无序列表项目符号 | • |
| \labelitemii | 第2层无序列表项目符号 | – |
| \labelitemiii | 第3层无序列表项目符号 | * |
| \labelitemiv | 第4层无序列表项目符号 | . |
| \leftmargini | 第1层列表项目的缩进 | |
| \leftmarginii | 第2层列表项目的缩进 | |
| \leftmarginiii | 第3层列表项目的缩进 | |
| \leftmarginiv | 第4层列表项目的缩进 | |
| \itemindent | 项目前的额外缩进 | 0 |
| \labelsep | 标签与内容的空白 | .5em |
| \labelwidth | 标签的宽度 | 2em或1.5em(双栏) |
| \listparindent | 项目的第二段起的额外缩进 | 0pt |
| \rightmargin | 列表右侧与外围环境外侧的距离 | 0pt或\leftmargin(quote、quotation或verse中) |
| \itemsep | 项目间垂直距离 | 2pt plus1pt minus1pt或3pt plus2pt minus1pt或4.5pt plus2pt minus1pt |
| \parsep | 同一项目中段落间距 | \itemsep. |
| \topsep | 首个项目与上一段的间距 | 8pt plus2pt minus4pt、9pt plus3pt minus5pt、10pt plus4pt minus6pt |
| \partopsep | 列表环境开新段的话要加到\topsep的量 | 2pt plus1pt minus1pt、3pt plus1pt minus1pt、3pt plus2pt minus2pt |
| \floatpagefraction | 浮动体页由浮动体占的最少比例 | .5 |
| \textfraction | 文本页中文本占的最小比例 | .2 |
| \topfraction | 在浮动体之前可占的页顶比例 | .7 |
| \floatsep | 页顶或页底的浮动体间距 | 12pt plus2pt minus2pt |
| \intextsep | 浮动体与上下文本的间距 | 12pt plus2pt minus2pt,14pt plus4pt minus4pt(对12pt) |
| \textfloatsep | 浮动体与页边的垂直间距 | 20pt plus2pt minus4pt |
| \bottomnumber | 页底最多容许的浮动体数 | 1 |
| \topnumber | 页顶最多容许的浮动体数 | 2 |
| \totalnumber | 文本页最多容许的浮动体数 | 3 |
| \arrayrulewidth | 表格中垂直分隔线粗 | .4pt |
| \arraystretch | 表格中行间空白比例 | 1 |
| \doublerulesep | 表格中紧接垂直分隔线间距离 | 2pt |
| \tabcolsep | 表格中列间空白的一半 | 6pt |
正文以外
题目
| 命令 | 用途 |
|---|---|
| \maketitle | 生成题目(非article会在单独页) |
| \author{name \and name2} | 指定作者,用\and分隔多个作者,用\\分隔同一作者的多行信息 |
| \date{text} | 指定日期,默认用当前日期 |
| \thanks{text} | 指定标题的脚注 |
| \title{text} | 指定标题,可用\\强制分行 |
目录
\tableofcontents、\listoffigures、\listoftables用于生成目录,目录有标题但目录后后不会换页。
\addcontentsline{ext}{unit}{text}新增一个条目,ext指定辅助文件后缀如toc(目录)、lof(图片目录)、lot(表格目录),unit指定单元如part、chapter、section、subsection、subsubsection、lof或lot,text为条目内容。\addtocontents{ext}{text}则直接把条目写到辅助文件。
词汇
| 命令 | 用途 | |
|---|---|---|
| \makeglossary | 容许生成词汇 | |
| \glossary{text} | 生成词汇条目 | |
| \glossaryentry{text}{pageno} | 生成词汇条目 |
glossary包提供更多功能。
索引
| 命令 | 用途 | |
|---|---|---|
| \indexentry{text}{pageno} | 生成索引条目 | |
| \index{bar | see{foo}} | 生成索引条目 |
| \index{bar | seealso{foo}} | 生成索引条目 |
| \seename | See意思的文本 | |
| \alsoname | See also意思的文本 |
通常用程序makeindex排序.idx文件得.ind文件,用makeidx宏包的\printindex输出索引。另multind包支持多个索引。
计数器和长度
计数器
LaTeX使用的计数器包括:
part、chapter、section、subsection、subsubsection、paragraph、subparagraph、page、equation、figure、table、footnote、mpfootnote、enumi、enumii、enumiii、enumiv、\day、\month、\year
命令|用途 —|— \alph{计数器}|用a、b、……格式化计数器的值 \Alph{计数器}|用A、B、……格式化计数器的值 \arabic{计数器}|用1、2、……格式化计数器的值 \roman{计数器}|用i、ii、……格式化计数器的值 \Roman{计数器}|用I、II、……格式化计数器的值 \fnsymbol{计数器}|用∗、†、‡、§、¶、k、∗∗、††、‡‡格式化计数器的值 \usecounter{计数器}|the second argument of the list environment to specify counter to be used to number the list items. \value{计数器}|引用计数器的值 \setcounter{计数器}{值}|设置计数器的值 \addtocounter{计数器}{值}|把值加到计数器 \refstepcounter{计数器}|把计数器加一并设置为当前的\ref值 \stepcounter{计数器}|把计数器加一
长度
| 命令 | 用途 |
|---|---|
| \setlength{\len}{value} | 指定\len的值,可用单位如in、mm、pt、bp |
| \addtolength{\len}{amount} | 把长度amount(可负)加到\len的值 |
| \settodepth{\len}{text} | 把\len的值设为文本text的深度 |
| \settoheight{\len}{text} | 把\len的值设为文本text的高度 |
| \settowidth{\len}{text} | 把\len的值设为文本text的宽度 |
预定义的长度有\width、\height、\depth、\totalheight,常用于指定盒子的自然大小。
扩充LaTeX
| 命令 | 用途 |
|---|---|
| \newcommand[*]{cmd}[nargs][optarg]{defn} | 定义命令cmd,它有nargs个参数,有optarg时它是首个参数的默认值,定义defn中可用#n引用第n个参数,*表示参数不能有多段 |
| \renewcommand[*]{cmd}[nargs][optarg]{defn} | 重定义命令,它有nargs个参数,有optarg时它是首个参数的默认值,定义defn中可用#n引用第n个参数,*表示参数不能有多段 |
| \newcounter{cnt}[countername] | 新增计数器cnt并初始化为0,countername增加时重设cnt为0 |
| \newlength{\arg} | 定义长度\newlength为0 |
| \newsavebox{cmd} | 定义\cmd为保存盒子的桶 |
| \newenvironment[*]{env}[nargs][default]{begdef}{enddef} | 定义环境 |
| \renewenvironment[*]{env}[nargs]{begdef}{enddef} | 重定义环境 |
| \newtheorem{newenv}{label}[within] | 定义定理类型环境newenv,名为label,编号随定理类型环境在单元within改变时重设 |
| \newtheorem{newenv}[numbered_like]{label} | 定义定理类型环境newenv,名为label,编号随定理类型环境numbered_like |
| \newfont{cmd}{fontname} | 定义命令\cmd,它使当前字体设为fontname.tfm |
| \protect | 放在一些上下文中脆弱命令前 |
特殊符号
文本符号
| 命令 | 特殊符号 |
|---|---|
| # | # |
| $ | $ |
| \% | % |
| \& | & |
| _ | _ |
| { | { |
| } | } |
| \copyright | © |
| \textcopyright | © |
| \dag | † |
| \ddag | ‡ |
| \LaTeX | $\LaTeX$ |
| \guillemotleft | « |
| \guillemotright | » |
| \guilsinglleft | ‹ |
| \guilsinglright | › |
| \ldots | … |
| \dots | … |
| \textellipsis | … |
| \lq | ‘ |
| \P | ¶ |
| \textparagraph | ¶ |
| \pounds | £ |
| \textsterling | £. |
| \quotedblbase | „ |
| \quotesinglbase | ‚ |
| \rq | ’ |
| \S | § |
| \TeX | $\TeX$ |
| \textasciicircum | ^ |
| \textasciitilde | ~ |
| \textasteriskcentered | * |
| \textbackslash | \ |
| \textbar | | |
| \textbardbl | |
| \textbigcircle | |
| \textbraceleft | { |
| \textbraceright | } |
| \textbullet | • |
| \textcircled{letter} | |
| \textcompwordmark | |
| \textcapitalwordmark | |
| \textascenderwordmark | |
| \textdagger | † |
| \textdaggerdbl | ‡ |
| \textdollar | $ |
| \textemdash或— | — |
| \textendashak或– | — |
| \texteuro | e |
\textexclamdown或!` |
¡ |
| \textgreater | > |
| \textless | < |
| \textleftarrow | ← |
| \textordfeminine | |
| \textordmasculine | |
| \textperiodcentered | · |
\textquestiondown或?` |
¿ |
\textquotedblleft或` ` |
“ |
| \textquotedblright或’’ | ” |
\textquoteleft或` |
‘ |
| \textquoteright或’ | ’ |
| \textquotestraightbase | ‚ |
| \textquotestraightdblbase | „ |
| \textregistered | ® |
| \textrightarrow | → |
| \textthreequartersemdash | |
| \texttrademark | ™ |
| \texttwelveudash | |
| \textunderscore | _ |
| \textvisiblespace |
重音
| 命令 | 效果 |
|---|---|
| "o | ö |
| 'o | ó |
| .o | ȯ |
| =o | ō |
| \^o | ô |
| `o | ò |
| ~o | õ |
| \b{o} | |
| \c{c} | ç |
| \d{o} | |
| \H{o} | ő |
| \i | ı |
| \j | ȷ |
| \k{o} | |
| \r{o} | o̊ |
| \t{o} | |
| \u{o} | ŏ |
| \v{o} | ǒ |
非英文字符
| 命令 | 效果 |
|---|---|
| \aa | å |
| \AA | Å |
| \ae | æ |
| \AE | Æ |
| \dh | ð |
| \DH | Ð |
| \dj | |
| \DJ | |
| \ij | ij |
| \IJ | IJ |
| \l | l |
| \L | L |
| \ng | |
| \NG | |
| \o | ø |
| \O | Ø. |
| \oe | œ |
| \OE | Œ |
| \ss | ß |
| \SS | SS |
| \th | þ |
| \TH | Þ |
其它
\rule[raise]{width}{thickness}用于生成方块,\today用于生成今天日期。
精细调整
空白
| 命令 | 用途 |
|---|---|
| \, | 窄空白(通常 1/6 quad) |
| \hspace{length} | 水平空白 |
| \hspace*{length} | 水平空白(即使在行首或行末也保留) |
| \hfill | 水平的弹性空白,胶水值0pt plus1fill’) |
| \ | 单词间的空白,通常用于控制序列后 |
| \@ | 结束句子的空白,通常用于大写字母后 |
| \thinspace | 1/6 em的水平空白,用于分隔嵌套引号 |
| \/ | 斜体校正 |
| \hrulefill | 弹性水平实心填充 |
| \dotfill | 弹性水平点填充 |
| \addvspace{length} | 使当前位置的垂直空白至少为length |
| \bigskip | 相当于\vspace{bigskipamount},约一行的高度 |
| \medskip | 相当于\vspace{medskipamount},约半行的高度 |
| \smallskip | 相当于\vspace{smallskipamount},约四分之一行高度 |
| \vfill | 弹性垂直空白 |
| \vspace{length} | 垂直空白 |
| \vspace*{length} | 垂直空白(即使在页顶或底也保留) |
盒子
| 命令 | 用途 |
|---|---|
| \mbox{text} | 生成刚能容纳text的盒子,不分行 |
| \fbox{text} | 生成刚能容纳text的带边框盒子,不分行,边框粗\fboxrule(默认.4pt),与内容相距\fboxsep(默认3pt) |
| \framebox[width][position]{text} | 生成指定宽度和对齐的带边框盒子,不分行,边框粗\fboxrule(默认.4pt),与内容相距\fboxsep(默认3pt) |
| \begin{lrbox}{cmd} text \end{lrbox} | \sbox的环境版本 |
| \makebox[width][position]{text} | 生成盒子,其中position可为c(居中,默认)、l(左对齐)、r(右对齐)或s(伸展) |
| \parbox[position][height][inner-pos]{width}{text} | 生成段落模式的盒子,其中position和inner-pos可为t(靠上,默认)、c(居中)、b(靠下)、s(伸展) |
| \raisebox{distance}[height][depth]{text} | 提升text共distance(负则下降),可把text视为有指定的高度和宽度 |
| \savebox{\boxcmd}[width][pos]{text} | 把如makebox生成的盒子放到\boxcmd |
| \sbox{\boxcmd}{text} | 把对text放到\boxcmd的盒子如mbox |
| \usebox{\boxcmd} | 生成最近保存到\boxcmd的命令对应的盒子 |
杂项命令
| 命令 | 用途 |
|---|---|
| \include{file} | 读入文件,再开新页,不能用于导言区或被include的文件 |
| \includeonly{file1,file2,…} | 只有对指定文件的包含有效,其它忽略,只用于导言区 |
| \input{file} | 读入文件,若后缀非.tex将加上这后缀,找不到才再试原文件 |
| \typein[\cmd]{msg} | 编译时在终端输出msg提示用户输入一行,该行作为\cmd定义或包含到当前位置 |
| \typeout{msg} | 编译时在终端和日志输出msg |
beamer
beamer宏包用于制作幻灯片。只用在文类中用beamer即可启用它,其中大部分LaTeX的命令和环境仍然可用。每张幻灯片形如:
\begin{frame}
\frametitle[短标题]{标题}
\framesubtitle{小标题}
%内容
\end{frame}
Beamer有一些现成主题用于调整外观(不怕麻烦也可用更底层的命令微调):
| 命令 | 用途 |
|---|---|
| \usetheme[⟨options⟩]{⟨name list⟩} | 设置主题 |
| \usecolortheme[⟨options⟩]{⟨name list⟩} | 设置颜色主题 |
| \usefonttheme[⟨options⟩]{⟨name⟩} | 设置字体主题 |
| \useinnertheme[⟨options⟩]{⟨name⟩} | 设置内部主题 |
| \useoutertheme[⟨options⟩]{⟨name⟩} | 设置外部主题(控制页眉、页脚、导航和标题) |
关于各主题及其外观,参看自带文档beameruserguide.pdf。
ctex
支持中文的最容易方法是用ctex宏包的文类ctexart、ctexrep、ctexbook代替article、report、book文类,并用xelatex编译。进一步的设置参看其文档。
其它常用宏包
| 宏包 | 用途 |
|---|---|
| geometry | 控制页面布局 |
| fancyhdr | 定制页眉和页脚 |
| tocloft | 定制目录 |
| calc | 算术运算 |
| graphicx | 插图,用法如\includegraphics[width=10cm]{image/logo.png} |
| amsmath | 数学相关 |
| amssymb | 更多数学符号 |
| amsthm | 标准的定理环境 |
| listings | 代码语法加亮 |
| hyperref | 链接,用法如\href{url}{text} |
| longtable | 跨页长表格 |
| endnotes | 篇末注 |
| algorithm2e | 排版算法 |
辅助工具
bibtex
bibtex是一个参考文献管理系统,只用维护一个bib文件列出可能用到的参考文献条目(各大科技期刊和学术搜索网站都有提供bib格式的条目可直接复制),并在TeX文件中加入
\bibliographystyle{bib风格}
\bibliography{bib文件,...}
其中bib风格可为alpha(字母序,标签为作者和年份)、plain(字母序,标签为编号)、unsrt(引用顺序,标签为作者和年份)、abbrv(引用顺序,标签为紧凑的作者和年份)等等。在编译时先运行一次tex引擎,然后运行一次bibtex,再运行两次tex引擎,当然,最好写成shell脚本或makefile。这样只有用cite或nocite引用的参考文献会被列出,在写多篇文章时特别方便:只用维护一个参考文献库。
基本的bib文件由一系列这样的条目组成:
@类型{项目=值,...}
| 类型 | 用途 | 必填项 | 可选项 |
|---|---|---|---|
| article | 期刊的文章 | author, title, journal, year | volume, number, pages, month, note |
| book | 出版的书 | author 或 editor, title, publisher, year | volume 或 number, series, address, edition, month, note |
| booklet | 小册子 | title | author, howpublished, address, month, year, note |
| conference | 同inproceedings | ||
| inbook | 书的一部分 | author 或 editor, title, chapter 和/或 pages, publisher, year | volume 或 number, series, type, address, edition, month, note |
| incollection | 书的一具名部分 | author, title, booktitle, publisher, year | editor, volume 或 number, series, type, chapter, pages, address, edition, month, note |
| inproceedings | 会议论文 | author, title, booktitle, year | editor, volume 或 number, series, pages, address, month, organization, publisher, note |
| manual | 技术文档 | title | author, organization, address, edition, month, year, note |
| mastersthesis | 硕士论文 | author, title, school, year | type, address, month, note |
| misc | 杂项 | author, title, howpublished, month, year, note | |
| phdthesis | 博士论文 | author, title, school, year | type, address, month, note |
| proceedings | 会议论文集 | title, year | editor, volume or number, series, address, month, organization, publisher, note |
| techreport | 技术报告 | author, title, institution, year | type, number, address, month, note |
| unpublished | 没有出版的文档 | author, title, note | month, year |
总结
TeX的排版算法是优秀的,质量有目共睹。不过,TeX作为一种语言有严重的缺陷,例如基于文本替换的宏和动态作用域就使得TeX代码往往做不到模块化,结果是TeX中各种宏包间经常会冲突。然而,由于人们已在TeX上投入了巨大的精力,编写了大量各种用途的宏包,在科技文献的排版中TeX仍是事实标准。