十个字号开关,以及一个字号开关到底改了什么
LaTeX 写作过程中从不问你要多少磅。你沿着一串具名的台阶上下挪:\tiny、\scriptsize、\footnotesize、\small、\normalsize、\large、\Large、\LARGE、\huge、\Huge,每一级等于多少磅由文档类说了算。这层间接性是故意的:基准尺寸改一次,十级台阶、行距和公式上下间距就一起跟着挪,一份九十页的报告因此不必重新调一遍。
标准 article 类在默认 10pt 基准上的十级是 5、7、8、9、10、12、14、17、20、24pt,配套行距是 6、8、9.5、10、12、14、18、22、24、28pt。台阶并不等距:\small 到 \normalsize 是 1.11 倍,\normalsize 到 \large 是 1.2 倍,\LARGE 到 \huge 是 1.18 倍。凭记忆背这些数字的人最好照本节最后一段的办法自查一次,因为换一个文档类或一个类选项,整列数字全部重排。
一个字号开关同时做四件事:按新尺寸选字体;设 \baselineskip,也就是基线到基线的标称距离;重置 \lineskip 与 \lineskiplimit,当相邻两行含有分数或行间公式这类高物件时由它们接管;并重定义周围的间距寄存器,例如 \abovedisplayskip 和 \belowdisplayshortskip,所以 \small 之后的行间公式比 \normalsize 之后的同一条贴得更紧。这份清单里没有一项是「只改字形大小」,手册才把它们称作 size changing 命令而不是字体命令。
想知道自己的文档真正解析出了哪些数字,把它写进日志而不是写进页面:在被测的组里写 \makeatletter \typeout{large = \f@size pt on \f@baselineskip pt}\makeatother。\f@size 与 \f@baselineskip 是每个字号开关都会定义的两个内部宏,\typeout 把文字送往 .log,而 \makeatletter 是这些带 @ 的名字能被写出来的前提。想让 TeX 停下来直接回答,就用交互式的 \showthe\baselineskip。
声明、组,以及为什么段末命令必须写在大括号里
这十条命令全都是声明:不带参数,只在当前组结束前有效。基础系统里不存在 \textlarge{...} 这种写法——\text… 形式只为家族、字重、字形这三种属性准备——所以一次字号改动的范围就是包住它的那对花括号:{\large … }。忘写花括号,就是一个孤零零的 \large 把文档剩下四页统统变成大字号。
段末位置之所以要紧,理由是纯粹的机械规则。TeX 取行距用的是这一行被送进竖排列表当时生效的 \baselineskip,而段落最后一行是在处理 \par 时才被送进去的。于是 {\large text text\par} 里连最后一行也按大行距排;而 {\large text text}\par 先由右括号退回 \normalsize,就恰好有一行与相邻行的距离错了。把 \par,或者代表它的空行,写在组内。
环境会替你分组。\begin{quote}\small …\end{quote} 不必自己加 \par 也安全,因为 \end{quote} 是在环境作用域内结束段落的。\begin{center}、\begin{tabular} 的单元格、脚注和图题同理——这也是脚注比正文小的原因:文档类替你给脚注内容套上了 \footnotesize。
有一个坑贯穿以上全部:\normalfont 常被拿来「撤销」字号改动,可它根本不碰尺寸。它只把家族、字重、字形恢复成文档默认值,尺寸仍是当前这一档。要回到正文字号必须显式写 \normalsize;要把正文观感整体复原,两者都得写。
粗体、斜体、倾斜、小型大写:两个属性不是一个
LaTeX 的字体选择方案用五种属性描述任何字体:编码、家族、字重、字形、尺寸。粗细属于字重——\mdseries(m)对 \bfseries(bx,bold extended);倾斜度属于字形——\upshape(n)、\itshape(it)、\slshape(sl,把正体设计直接压斜)与 \scshape(sc,小型大写)。每个属性都有声明形式和带参数的命令形式:\bfseries/\textbf、\itshape/\textit、\slshape/\textsl、\scshape/\textsc、\upshape/\textup、\mdseries/\textmd。行文中优先用 \text… 形式,因为范围在源码里看得见,不会外溢。
字体是按属性的名字去要的,LaTeX 只能给你确实存在的东西。\textbf{\textit{...}} 同时要求 bx 字重与 it 字形,而 Computer Modern——以及它的矢量后继 Latin Modern——没有粗斜体文本字体。LaTeX 换上最接近的一款,并在日志里告诉你:Font shape `T1/cmr/bx/it' undefined, using `T1/cmr/bx/n' instead。页面上看到的是粗正体,不读日志就完全察觉不到。解决办法是换一套确实带这个字形的字族(Times 观感走 newtxtext 或 mathptmx,Palatino 走 newpxtext 或 mathpazo),或者用 fontspec 配任何四个面齐全的操作系统字体。
\emph 不是 \textit 的同义词。它要的是强调,实现方式是感知字形、可以嵌套:在正体文本里给出斜体,在斜体文本里退回正体并把周围文字重新斜排。这才是排版上正确的行为,也是风格指南要求写 \emph、把 \textit 留给「这几个词确实要以斜体出现」的原因。
数学另有一套并行的开关,而且不跟随文本字体。\mathrm、\mathbf、\mathit、\mathsf、\mathtt 切的是数学字族;\mathbf 只认字母和数字,所以 \mathbf{\pi} 仍是普通的 π——要的是 amsfonts 里的 \boldsymbol{\pi},或 bm 宏包的 \bm{\pi},后者连运算符和定界符也能加粗。\pmb 靠叠印一份位移副本伪造粗体,任何字形都能应付,代价是边缘略微发虚。
\mathrm{d}x \quad \mathbf{A}\mathbf{b} \quad \mathit{u} \quad \mathtt{code} \quad \mathsf{H} \quad \boldsymbol{\Omega} \quad \mathbb{R} \quad \mathcal{O}
\mathbf 动不了 π,\boldsymbol 与 \pmb 动得了。\mathbf{\pi} \quad \boldsymbol{\pi} \quad \pmb{\pi} \quad \pi
选字族:编码、Latin Modern 与值得加载的宏包
几乎每份文档开头那两行,比后面任何字体命令都管用。\usepackage[T1]{fontenc} 要求用 8-bit 西欧字体编码,取代更老的 OT1;\usepackage{lmodern} 接着载入 Latin Modern,也就是矢量重绘的 Computer Modern,字形更多、提示更好。在 OT1 下,\'e 这类重音字母是在输出时由独立重音符号和字母 e 临时拼成的,于是断词器无法在词内断开,读者从 PDF 里复制出来的是「´e」而不是「é」,带重音的 \textsc 甚至可能整个缺失。T1 有预组合好的字位,这些毛病一次消失——代价是字形名称变了(T1/cmr/m/n 而非 OT1/cmr/m/n),个别标点周围的字距略松。
要换正文字体本身,请加载宏包而不是手工重定义 \rmdefault。Times 观感用 newtxtext 配 newtxmath;mathptmx 是等价的老办法,times 已经过时——它只改文本字族,数学仍是 Computer Modern,两者一对照就很刺眼。Palatino 用 newpxtext 加 newpxmath,或 mathpazo;想要 Palatino 那一类书籍字体还有 tgpagella;Charter 则用 XCharter。让文档保持正常的铁律是:文本与数学一起换,否则都别换。
两个伴生字体可以按片段切换而不动正文字体:无衬线用 \textsf{...}/\sffamily,等宽用 \texttt{...}/\ttfamily,背后由 helvet、tgheros、courier、tgtt 撑腰。Helvetica 在视觉上比多数正文字体宽,所以 helvet 提供 scaled=0.92 选项(couriers 是 scaled=0.8)。要把无衬线变成默认,在导言区写 \renewcommand{\familydefault}{\sfdefault};这条声明在文档类于 \begin{document} 处选 \normalfont 时才生效。
换到 XeLaTeX 或 LuaLaTeX,整套 8-bit 层直接消失,由 fontspec 接管:\setmainfont、\setsansfont、\setmonofont 接受系统字体名,任何 Unicode 字符都能直接敲,\setmainfont{...}[BoldFont=..., SmallCapsFont=...] 还能单独指定某一面。数学这时要 unicode-math。不要把两个世界混起来——fontspec 与 fontenc、inputenc 同时加载,是从 pdfLaTeX 模板迁往 XeLaTeX 时最常见的崩溃。
\documentclass[11pt]{article}
% Text encoding first, then the fonts. With XeLaTeX or LuaLaTeX you delete
% these two lines and load fontspec instead.
\usepackage[T1]{fontenc}
\usepackage{lmodern}
% Times-like text with matching maths (instead of the obsolete "times").
\usepackage{newtxtext}
\usepackage{newtxmath}
% Sans and typewriter companions, both optically scaled down a little.
\usepackage[scaled=0.92]{helvet}
\usepackage[scaled=0.8]{couriers}
\usepackage{bm} % \bm{...} bolds symbols that \mathbf cannot reach
\begin{document}
\textnormal{Roman (the default family).} \quad
\sffamily{Sans serif.} \quad
\ttfamily{Typewriter.} \normalfont
\textbf{Bold.} \textit{Italic.} \textsl{Slanted.} \textsc{Small caps.}
\emph{Emphasis, which inside \emph{italic} turns upright instead of doubling
the italic shape.} \textup{Upright again.}
\textbf{\textit{Bold italic}} -- with Computer Modern or Latin Modern this
prints \emph{bold upright}, because no bx/it shape exists in those families;
the log says so: \texttt{Font shape `T1/cmr/bx/it' undefined}.
Maths keeps its own font switches, independent of the text family above:
\[
\mathrm{rank}(A) \quad \mathbf{A}\mathbf{x} = \mathbf{b} \quad
\bm{\omega} \times \mathbf{r} \quad \mathcal{L}(\theta) \quad \mathbb{E}[X]
\]
\end{document}
数学另有自己的四级尺寸梯
数学内部的大小不是那十级台阶,而是四种样式:\displaystyle、\textstyle、\scriptstyle、\scriptscriptstyle。TeX 替你选:行间公式用 display 样式,行内数学用 text 样式,下标降一级,下标的下标降到 scriptscript。看得见的差别不只是尺寸——display 样式把 \sum、\int 的上下限摆在运算符上下方,text 样式把它们挪到右侧,分数也按同一条规则压缩自己的内容。
相邻级的比例大致是当前尺寸的 0.7 与 0.5,而「当前」指的是包围这段数学的文本尺寸。这就是 {\small …} 会连带缩小整段行内分数的原因,也是在小字号段落里强推 \displaystyle 会顶出一行高出邻居的东西的原因:你改了尺寸,却没改所在段落的行距。
强制指定样式有两条路:分数用 amsmath 的简写 \tfrac、\dfrac、\cfrac,其余场景在组的开头写 \displaystyle。最常需要的是 array、matrix、cases 里面——这些环境默认按 text 样式排版,除非每个单元格自己写 \dfrac 或以 \displaystyle 开头,嵌套分数就会缩小。
定界符的尺寸是另一套机制:\left/\right 把括号撑到组内最高物件的高度,而 \bigl、\Bigl、\biggl、\Biggl(配上对应的 r 形式)走的是四个固定档位。自动撑高配上高分数往往过头,而且它跨不过 & 对齐单元格,这就是对齐公式几乎总改用手工档位的原因。
\displaystyle \sum_{n=1}^{\infty} \frac{1}{n^{2}} = \frac{\pi^{2}}{6} \qquad \sum_{n=1}^{\infty} \frac{1}{n^{2}} \qquad \scriptstyle \sum_{n=1}^{\infty} \frac{1}{n^{2}} \qquad \scriptscriptstyle \sum_{n=1}^{\infty} \frac{1}{n^{2}}
文档类没给的基准字号
标准文档类只接受三个基准字号:10pt、11pt、12pt,以类选项给出。每个选项做的事就是载入另一个文件——size10.clo、size11.clo、size12.clo——里面写着十级台阶和配套行距。写 \documentclass[14pt]{article} 并不会给你 14pt:这个选项不认识,文档类照 10pt 继续跑,日志里留下一行很容易被忽略的记录:Unused global option(s): "14pt"。这一行就是全部诊断,也是为什么「选项没起作用」属于读日志的功课,而不是 bug 报告。
其他任何基准字号都有四条干净的路。extsizes 带 extarticle、extreport、extbook,选项覆盖 8、9、10、11、12、14、17、20pt,接口与标准类完全一致。KOMA-script 在自己的类上用 fontsize=13pt,其 scrextend 宏包把同一个键带进非 KOMA 的类:\usepackage[fontsize=13pt]{scrextend}。fontsize 宏包提供 \changefontsize{13pt} 和 \SelectThisToChangeTheDocumentBaseSize。XeLaTeX 或 LuaLaTeX 下则改为缩放字体:\setmainfont{...}[Scale=1.05]。
验证结果用与第一节相同的日志手法:\makeatletter \typeout{base \@ptsize}\makeatother 对三个标准值分别打印 0、1、2;在 {\normalsize … } 里写 \typeout{leading \f@baselineskip},打印文档类选定的段落行距。
动用这些之前先分清:抱怨的是字号还是间距。觉得版面发挤的页面通常缺的是行距而不是磅数——导言区一句 \linespread{1.05}\selectfont 会放松每一行,其中 \selectfont 不是装饰,因为 \linespread 只存一个倍率,新值要等下一次选字号才被应用。setspace 宏包把这一对包装成 \setstretch{1.05},并让列表与图题的间距保持一致;它属于版面那一课,垂直节奏的其余部分都在那里。
\begin{array}{ll} \text{encoding} & \texttt{T1 / OT1 / TU} \\ \text{family} & \texttt{rmfamily / sffamily / ttfamily} \\ \text{series} & \texttt{mdseries / bfseries} \\ \text{shape} & \texttt{upshape / itshape / slshape / scshape} \\ \text{size} & \texttt{tiny \ldots Huge} \end{array}
% A base size the standard classes do not offer. Pick ONE of the four routes
% below; the rest are commented out so the file still compiles.
% Route 1 -- the extsizes bundle: 8, 9, 10, 11, 12, 14, 17, 20 pt, and it
% ships extarticle/extreport/extbook with the same interfaces as the standard
% classes.
\documentclass[14pt,a4paper]{extarticle}
% Route 2 -- KOMA-script's standalone shim, works with any class:
% \documentclass[a4paper]{article}
% \usepackage[fontsize=13pt]{scrextend}
% Route 3 -- KOMA-script classes carry it natively:
% \documentclass[fontsize=13.5pt,paper=a4]{scrartcl}
% Route 4 -- XeLaTeX/LuaLaTeX: scale the loaded font instead of the ladder.
% \documentclass[a4paper]{article}
% \usepackage{fontspec}
% \setmainfont{TeX Gyre Pagella}[Scale=1.05]
\usepackage[T1]{fontenc}
\usepackage{caption}
\begin{document}
% What the class actually resolved the rungs to -- look in the .log file.
\makeatletter
\typeout{base \@ptsize\space pt; normalsize on \f@baselineskip\space pt leading}
\makeatother
\section{Captions and tables take their size from the class, not from you}
\begin{table}[ht]
\centering
\small % shrinks the tabular ...
\captionsetup{font=normalsize} % ... but not this caption
\begin{tabular}{lrr}
\hline
Sample & $n$ & Mean \\
\hline
A & 120 & 4.18 \\
B & 145 & 3.90 \\
\hline
\end{tabular}
\caption{\texttt{\textbackslash small} applies to everything inside the
environment, so the caption has to be opted out explicitly.}
\end{table}
{\Huge\bfseries A display line in the middle of the page\par}
\noindent and the body text resumes at \normalsize immediately afterwards,
because the braces ended the declaration's scope.
\end{document}
四条覆盖大多数真实需求的配方
表格字小一点,图题保持正常。紧跟 \begin{table} 的 \small 会把整块连图题一起缩小,因为执行到 \caption 时声明还在作用域里。加载 caption 并在同一段里补 \captionsetup{font=normalsize},或者把字号改动收进只包 tabular 的那个组。
一小段附注式小字。用会替你分组、又会替你收尾段落的环境:\begin{quote}\small … \end{quote}。别用 \vspace 加字号声明再加手工 \par 去凑,那样要么范围外溢要么行距不对,而环境还白送一个缩进。
页面中间来一行特大字。{\Huge\bfseries …\par},若下一段不想缩进就补一个 \noindent。如果那一行本质上是标题,就该去改标题样式:用 titlesec 写 \titleformat{\section}{\LARGE\bfseries}{}{0em}{},用 KOMA-script 写 \addtokomafont{section}{\LARGE}。手工塞进标题的字号既撑不过一次文档类更换,也不会连同其它样式一起出现在目录里。
脚注更小,或者更大。文档类在每个脚注内部施加 \footnotesize,标准类的图题和表格附注也用同一级,所以 \renewcommand{\footnotesize}{\scriptsize} 会顺手把你的图题一起缩小。KOMA-script 用 \addtokomafont{footnote}{\scriptsize} 把这件事隔离开;否则就去重定义内部的 \@makefntext 那一段,而不是重定义尺寸名。
\documentclass[10pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{amsmath}
\begin{document}
\section*{The ten rungs, in one paragraph each}
{\tiny tiny -- the smallest rung the class defines.\par}
{\scriptsize scriptsize -- footnote-of-a-footnote territory.\par}
{\footnotesize footnotesize -- what captions and \texttt{footnote} bodies use.\par}
{\small small -- tables, and anything you want to fit without shrinking the page.\par}
{\normalsize normalsize -- the base size, set by the class option, not by you.\par}
{\large large -- subheadings in many classes.\par}
{\Large Large -- capital L, one rung above \texttt{\textbackslash large}.\par}
{\LARGE LARGE -- two capital Ls.\par}
{\huge huge -- lower-case h.\par}
{\Huge Huge -- the top rung, 24pt on a 10pt base.\par}
\section*{Where a size change belongs}
% Right: the paragraph break is inside the group, so the final line keeps
% the leading that \large selected.
{\large This sentence is long enough to wrap, and the \par inside the braces
is what stops the last line from being spaced on the outer baselineskip.\par}
% Wrong: the group closes first, so exactly one line comes out tight.
{\large This sentence is long enough to wrap, and the paragraph break falls
outside the braces, which is how the last line ends up with the wrong
distance to the line above it.}\par
% Right again: the quote environment groups the text and ends the paragraph
% inside that group, so no \par of your own is needed.
\begin{quote}
\small
A quote environment already scopes the declaration for you, and
\verb|\end{quote}| closes the paragraph while still inside that scope.
\end{quote}
\end{document}
本课速查
每节抽一行关键代码:点小节名跳到对应位置,代码一键复制。
\mathrm{d}x \quad \mathbf{A}\mathbf{b} \quad \mathit{u} \quad \mathtt{code} \quad \mathsf{H} \quad \boldsymbol{\Omega} \quad \mathbb{R} \quad \mathcal{O}
\documentclass[11pt]{article}
\displaystyle \sum_{n=1}^{\infty} \frac{1}{n^{2}} = \frac{\pi^{2}}{6} \qquad \sum_{n=1}^{\infty} \frac{1}{n^{2}} \qquad \scriptstyle \sum_{n=1}^{\infty} \frac{1}{n^{2}} \qquad \scriptscriptstyle \sum_{n=1}^{\infty} \frac{1}{n^{2}}
\documentclass[14pt,a4paper]{extarticle}
\documentclass[10pt,a4paper]{article}
常见错误
{\large 正文}把右括号写在段落结束之前:最后一行按组外的\baselineskip排,唯一症状就是那一行不齐。\par(或代表它的空行)要写在大括号里面。- 直接打一个
\large外面不套组,让它一路跑到文档结尾。每个字号开关都是声明,范围是包住它的组;在顶层,这个范围就是文件的余下全部。 - 以为 Computer Modern 或 Latin Modern 下
\textbf{\textit{…}}会印出粗斜体。两个家族都没有 bx/it 字形,LaTeX 换成 bx/n,唯一的证据是日志里那行Font shape … undefined。 - 用
\normalfont去撤销字号改动。它只在当前尺寸下重置家族、字重、字形;你还需要\normalsize。 \documentclass[14pt]{article}——标准类没有这个选项。构建照 10pt 成功,日志留下一句Unused global option(s)。改用extsizes、scrextend,或在 KOMA 类上写fontsize=…。- 用老式声明
\rm、\bf、\it而不是\rmfamily、\bfseries、\itshape。被淘汰的形式按固定尺寸取字体,于是\large\bf 正文给你的是 10pt 的粗体而不是大字号的粗体。 - 加载
times之后纳闷正文像 Times 而每个公式仍是 Computer Modern 的样子:这个宏包只改文本字族。要用newtxtext配newtxmath,或者用mathptmx。
关于本课的常见问题
LaTeX 怎么把文字变大?
\large ... \par}。基础系统里没有 \textlarge{...} 这种命令,起作用的边界就是右括号,漏掉括号等于让后面一切都变大。只想改一个词时应该去缩放字体而不是选级别:\Large 是一级台阶,不是带参数的命令。\large、\Large 和 \LARGE 有什么区别?
\Llarge 或 \HUGE,所以写错大小写得到的是 Undefined control sequence,不会悄悄降级到别的档位。为什么 LaTeX 的粗斜体没生效?
\textbf{\textit{text}} 被替换成粗正体,日志报一行 Font shape `T1/cmr/bx/it undefined。换一套四面齐全的字族(要 Times 观感用 newtxtext,要 Palatino 用 mathpazo),或改用 XeLaTeX、LuaLaTeX 配 fontspec 和任意系统字体。怎么改整篇文档的默认字号?
\documentclass[12pt]{article} 只接受 10pt、11pt、12pt。要别的尺寸就换 extsizes(extarticle 的选项最高到 20pt)、给任意类加 \usepackage[fontsize=13pt]{scrextend},或在 KOMA-script 类上写 fontsize=13pt。\documentclass[14pt]{article} 除了留下一行 Unused global option(s) 警告什么都不做。为什么 \footnotesize 把行距也一起改了?
\baselineskip 和周围行间公式的间距,这正是小字段落不会在行间出现过大空隙的原因。想要字形变小而行距不变,那是行距问题不是尺寸问题:\linespread{倍率}\selectfont,或者用 setspace 宏包。列表里没有的 13pt 怎么拿到?
\usepackage{fontspec} 配 \setmainfont{...}[Scale=1.08]。偶尔的超大号内容,\Huge 加上文档类定义的标题样式通常才是稳妥的回答。实时演示:直接编辑 LaTeX,立刻看渲染结果
预览随输入实时更新——不妨故意写坏一次,看看报错长什么样。
继续读
同一个东西的三个入口:记法本身、讲它的那一课、以及真正用它写东西的一篇文章。