阶段 2 · 文本与文档结构 13 / 48 ≈ 14 分钟读完

LaTeX 换行与间距:到底哪种写法真管用

双反斜杠结束一行,空行结束一个段落。这是两种不同的操作,结果也看得见,而新手文档里大多数间距问题都是在该用后者时用了前者。这一课把两者分开,列出强制换行确实是正确工具的四处位置,点出哪些寄存器拥有你的垂直空间,并给出能在不伪造换行的前提下修好超宽行的那几个旋钮。

    两条看着一样的操作:结束一行,结束一个段落

    源码里的一个空行就是一个 \par:它关掉段落,于是它后面的垂直胶是 \parskip 加一个基线距离,下一行被当作新段落的第一行来对待——也就是说它会按 \parindent 缩进。\\ 只停住当前这一行:段落还在继续,所以它下面那行不缩进,也不插入 \parskip,两行之间就是一个 \baselineskip,与段落里任何相邻两行没有区别。

    差别在三处看得见,而没人告诉你该往哪儿看。开着 \parindent 的文档里,空行之后那行会缩进,\\ 之后那行不会。用了 parskip 宏包的文档里,强制换行之后的空隙比段落之间小得多——常常小得多,这就是商业信函里 \\ 「不灵」的原因。而且以 \\ 收尾的那一行不做两端对齐:TeX 用一次显式断点把它截住,不让断行算法去挑位置,所以词不会铺到右边界,那个点上也不再考虑断词。

    底层上,\\ 就是带了可选参数的 \newline。内核还在这个断点前后保存并恢复空格因子,所以 \\ 前面那个句末句点不会带上句间的多余空格——段落若继续才会有那一份。这是手搓 TeX 断行从来拿不到的一点打磨。

    强制换行正确的地方恰好四处:tabular 或 array 的行之间,多行数学环境(aligned、gathered、cases、matrix)的行之间,center/flushleft/flushright 块内部以及它们为之存在的地址式材料,还有诗歌——诗的一行不是散文的一行。在普通行文里,它是一个症状,不是一种工具。

    \begin{array}{lll}\text{source} & \text{what it does} & \text{visible effect} \\\hline \texttt{double backslash} & \text{ends the line} & \text{no indent, no parskip} \\ \texttt{blank line} & \text{ends the paragraph} & \text{indent plus a gap} \\ \texttt{\textbackslash linebreak} & \text{asks for a break} & \text{line stays justified}\end{array}
    \begin{array}{lll}\text{source} & \text{what it does} & \text{visible effect} \\\hline \texttt{double backslash} & \text{ends the line} & \text{no indent, no parskip} \\ \texttt{blank line} & \text{ends the paragraph} & \text{indent plus a gap} \\ \texttt{\textbackslash linebreak} & \text{asks for a break} & \text{line stays justified}\end{array}
    Four visible differences between a forced line break and a paragraph break in LaTeX SOURCE ON THE LEFT, WHAT THE PAGE LOOKS LIKE ON THE RIGHT SAME PARAGRAPH: \ (A DOUBLE BACKSLASH) … the line ends here\\ and the next one starts without any new paragraph. not justified no indent on either following line; no \parskip glue anywhere; the page may still break between them NEW PARAGRAPH: A BLANK LINE ( = \par ) … the paragraph ends here % blank line and this one starts afresh. \parskip + one \baselineskip of glue \parindent on the first line only TeX is free to hyphenate to fill both lines DECIDING WHICH ONE YOU MEANT prose, continuing the argument prose, new idea rows of a tabular / array rows of aligned, cases, matrix an address block inside center blank line, never the backslash pair blank line double backslash is the only option double backslash, inside one maths object with one number double backslash — the block is not a paragraph of prose blank line blank line double backslash double backslash double backslash The right-hand column is a paragraph decision: it changes indent, glue and justification. The lower three are structural: the environment needs the break to mark where a row ends.
    强制换行停住一行;段末停住一个段落,并把下一行交给缩进和 parskip 规则。

    可选参数、星号,以及一次强制换行的代价

    \\[12pt] 在被结束的这行与下一行之间加垂直空间;\\* 禁止在此处断页,地址块或一联诗不被拆开靠的就是它。这两个选项就是用 \\ 而不是 \newline 的全部理由,后者两个都不接受。

    那个空间参数有一处写进文档的弱点,而且专在最要命的时候咬人:它插入的胶挂在断点上,所以 TeX 偏偏决定在此断页时,这段空间就随页面一起消失。页首的任何垂直胶同理,这正是星号形式存在的原因——\vspace*{20pt} 活得下来,\vspace{20pt} 会被丢弃。如果这一行空间真的承重(签名块、分隔开的诗节),稳的工具是 needspace 宏包的 \needspace{5\baselineskip}:它把整块推到下一页,而不是就地把它粘住。

    \linebreak[n] 与 \nolinebreak[n] 是客气的版本:一个 0 到 4 的数字给这个断点挂上罚值——内核的低、中、高档分别是 51、151、301,而 4 是要求不是请求。因为 TeX 仍然要跑自己的优化器,\linebreak[3] 所在那行照样两端对齐到边界,段落别处的断词仍可能胜出。\pagebreak[n] 与 \nopagebreak[n] 在页面层面做同一件事;写在列表条目最后一行紧接着的 \nopagebreak,是让该条目不被腰斩的最便宜的办法。

    两件从构造上就该避免的失败。\end{tabular} 之前最后那个 \\ 会多出一个空行——带可选参数时,多出的是一行纯粹的空间。而紧挨在行间公式前面的 \\ 会与文档类自己的公式间距打架:\[ 本来就另起一行,强制换行除了一行不齐和一个意外的大缝什么也不添加。

    \begin{aligned} f(x) & = x^{2} + 2x && \text{row one} \\ & = (x+1)^{2} - 1 && \text{row two} \end{aligned}
    \begin{aligned} f(x) & = x^{2} + 2x && \text{row one} \\ & = (x+1)^{2} - 1 && \text{row two} \end{aligned}
    在 aligned 里,双反斜杠不是新起段落的捷径:它结束的是同一个数学对象的一行,整个环境仍是一条公式、一个编号。

    TeX 怎么读你敲进去的那些空格

    在一行源码内部,一串空格、制表符和单个换行会塌缩成一件词间胶:word 加换行加 word,与 word word 完全等价。这就是专业源码把每个句子单独放一行、输出却一分不差的原因。空行是例外,因为它不是空格——它是 \par。

    行末的 % 是用来去掉一个空格而不是加一个空格的工具:它把该行余下的内容全部变成注释,连换行符本身也算在内,于是下一行源码不带任何胶地接上来。你会在这些地方需要它:以命令结尾的 tabular 单元格、\item 标签之后、任何一处多余空格会变成可见缝隙的地方,以及段落换行会致命的 \parbox 中间。

    要在 TeX 会吞掉空格的地方放一个空格,就敲一个控制空格 \ ——命令名之后(其后的空白按定义被吃掉),或者当你想要「50 cc」而不是「50cc」时。连字符 ~ 是相反的器具:一个断行永远不能用的空格,item~\ref{itm:psu}、Figure~3、2.4~GHz 里用的都是它。接下来是显式的跳过:\hspace{1em}(不写 plus 和 minus 就是刚性的)、\hfill(无限伸展,把材料推开就靠它)、\kern(刚性,而且与 \hskip 不同,不是一个可以断行的位置),以及具名宽度 \enspace、\quad、\qquad。一个 em 就是当前字号,所以它们全都随上一课那十级阶梯一起缩放。

    数学间距是一套独立系统,单位还更细:\,、\:、\; 是三个按 mu 缩放的缝,\! 收掉一个,而 \mathsf{abc} 与 abc 的差别就在 TeX 围绕运算符与关系自动插入的那层胶。别在公式里伸手去拿 \hspace:\mathop、\mathbin 和这一整套间距类的存在,就是为了让公式被缩进下标时仍然保住自己的间距。

    How whitespace in a LaTeX source file maps onto the page: newline, blank line, percent sign and runs of spaces THE SOURCE FILE, WITH EVERY WHITESPACE DECISION MARKED 1 words on one line, then a 2 newline in the file. 3 (an empty line here) 4 A second paragraph. 5 It ends with a percent: and 6 this line is glued on tight. 7 Many spaces in a row 8 are one space to TeX. one newline = one space a blank line = \par a % hides the rest of the line, including its break runs of spaces collapse THE RESULT ON THE PAGE \parskip + \baselineskip of glue, then an indent lines 5 and 6 became one line of text: line 7 is set as it would be with single spaces — TeX never sees the rest THE THREE THAT ARE WORTH MEMORISING newline one space so break a paragraph anywhere you like blank line \par indent + paragraph glue, so never two in a row percent at the end nothing the space is gone; this is how you join lines One newline is a space and ten are also one space; only the empty line changes the paragraph, and % changes it back.
    源码空白到输出的映射:单个换行是一个空格,空行是一个段落,百分号是行上的一个洞。

    垂直空间:归寄存器管,不归你的手指管

    LaTeX 页面上每一道缝都由一个具名寄存器持有,认出主人才能全局地修间距,而不是逐行去修。段落行间:\baselineskip,相邻两行都高时由 \lineskip 接管。段落之间:\parskip。列表上下:\topsep 与 \partopsep;列表内部:\itemsep 与 \parsep。正文与行间公式之间:\abovedisplayskip 与 \belowdisplayskip,前一行很短时换成它们的 short 变体。浮动体周围:\floatsep、\textfloatsep、\intextsep。图题之下:\abovecaptionskip。

    三个现成尺寸——\smallskip、\medskip、\bigskip(以及竖排模式下等价的 \…skip)——不是固定长度,而是文档类定义的带伸缩胶,所以在断页处行为正确;硬写的 \vspace{1cm} 就不行。\vfill 填满页面剩下的部分,这才是题头块或签名行真正想要的东西。

    写在行中间的 \vspace 不会把这一行剩下的部分往下推:垂直胶只在行与行之间有意义,于是这段空间要么加在你抵达的下一个断点处,要么被丢掉。在它前面写 \par(或者一个空行),或者改用 \\[space]。在页首,光秃秃的 \vspace 会被整个丢弃,只有 \vspace* 保得住尺寸。

    合法的结构性用法只有三种:\enlargethispage{\baselineskip}(以及它的星号形式)在某页特别糟时偷一行空间;\needspace{n\baselineskip} 保住一块不拆;以及上面某个寄存器的类级修改。其余都不算——\\ \\ 这一对、空的 ~\par、每个小节标题前的 \vspace——都是给全局问题打的局部补丁,文字一重排就会重新冒出来。

    \begin{array}{ll}\text{line to line} & \texttt{baselineskip} \\ \text{paragraph to paragraph} & \texttt{parskip} \\ \text{list above and below} & \texttt{topsep} \\ \text{text to equation} & \texttt{abovedisplayskip}\end{array}
    \begin{array}{ll}\text{line to line} & \texttt{baselineskip} \\ \text{paragraph to paragraph} & \texttt{parskip} \\ \text{list above and below} & \texttt{topsep} \\ \text{text to equation} & \texttt{abovedisplayskip}\end{array}
    Horizontal and vertical space commands in LaTeX compared: what each one is, whether it stretches, and which mode it is legal in HORIZONTAL SPACE — INSIDE A LINE COMMAND WHAT IT ADDS STRETCHES? CAN A LINE BREAK THERE? a space or one newline one inter-word glue yes yes backslash + space a space TeX cannot swallow yes yes ~ (the tie) a space that must stay yes no — that is the point \hspace{1em} rigid unless you write plus= only if you add it yes \hfill infinite stretch always yes \kern 6pt rigid shift, TeX primitive no no — use \hskip for that \quad \qquad \enspace 1 em, 2 em, half an em a little yes VERTICAL SPACE — BETWEEN LINES AND PAGES COMMAND / REGISTER WHAT IT SEPARATES SURVIVES A PAGE BREAK? MODE IT NEEDS \baselineskip two lines of one paragraph it is the page grid automatic \parskip two paragraphs yes, it is glue automatic at \par \vspace{12pt} anything you ask it to no — discarded at the top vertical mode \vspace*{12pt} the same, forced yes vertical mode \[12pt] after a break the next line, in one line pair no — it rides on the break horizontal
    左边是水平工具,右边是垂直工具,并标出各自合法的模式。

    overfull 与 underfull 行,以及能修好它们的旋钮

    TeX 靠最小化一个代价函数来断行:badness 量的是胶被拉伸或压缩了多少,demerits 惩罚糟糕的序列,断词另有自己的价。Overfull \hbox 意思是它找到的最便宜解仍比版心多出超过 \hfuzz 的量,于是那一行戳进了边距;Underfull \hbox 意思是一行被拉开来填满,看上去字距发散。两句都是关于你的文本的消息,不是关于编译器的。

    修复的有序清单:改写句子;在允许的地方让 TeX 断词(\hyphenpenalty 与 \exhyphenpenalty 抬高或压低价格,\doublehyphendemerits 与 \finalhyphendemerits 阻止连成一串的断词和末行断词);给优化器留一条最后的逃生通道 \setlength{\emergencystretch}{1em},它只在正常拉伸失败之后才生效,因此不会把整个文档放松;自己加宽或亲手打断出问题的那段材料;到这一步之后才去拿 \sloppy 或 sloppypar 环境——后者放松 \tolerance 等等值,为了消掉警告乐于产出一行丑字。

    长的不可断记号是另一类问题,也有另一套解法:URL、文件路径、驼峰标识符根本没法断词。hyperref 或 url 提供的 \url{...} 与 \path{...} 会在合理的字符处断开(xurl 能在任何地方断),单个顽固的词用 \allowbreak 或一个随时的 \- 就能处理。想看 TeX 选定的断词点,就在日志里问:\showhyphens{supernumerary} 会把它印出来;\hyphenation{pe-diat-ric} 按整份文档加例外,而不是用 \- 逐个词去补。

    有一个宏包对这些的疗效超过所有旋钮加起来:\usepackage{microtype} 加上 protrusion(圆字母和标点微微探出边距,于是每行多出一点余量),并且在 pdfLaTeX 或 LuaLaTeX 下加上字体扩展(同一字形再排一份 99.5% 宽度的)。把它放在最后加载,先看页面,然后再决定某一具体行是否还值得改写。

    \documentclass[10pt]{article}
    \usepackage[T1]{fontenc}
    \usepackage{array}
    \usepackage{amsmath}
    
    \begin{document}
    
    % ---- the three legitimate uses of an explicit line break ----
    \begin{tabular}{@{}ll@{}}
      Row one, cell one & Row one, cell two \\
      Row two           & still the same environment \\[4pt]
      A gap paid for by the row, not by an empty row
    \end{tabular}
    
    \begin{equation}
      \begin{aligned}
        (a+b)^{2} &= a^{2} + 2ab + b^{2} \\
                  &= (a-b)^{2} + 4ab
      \end{aligned}
    \end{equation}
    
    % ---- hyphenation you control instead of space you fake ----
    The word supernumerary is long, and a discretionary hyphen can be placed by
    hand: super\-nu\-mer\-ary. To see what TeX would have chosen anyway, ask it
    in the log with \verb|\showhyphens{supernumerary}|.
    
    % ---- two spaces in the source are exactly one space on the page ----
    Two   spaces      and          a   newline
    all collapse into one inter-word glue, and a blank line here ends the
    paragraph.
    
    % ---- the comment character eats the line break, so it eats the space ----
    This line ends with a percent sign and therefore joins the next one with
    no space at all:%
    this word follows immediately.
    
    \end{document}

    段落样式是一个决定,只做一次

    分隔段落只有两种做法,而每份文档都要二选一:首行缩进、段落之间不给额外空间(\parindent 开着、\parskip 为零,标准类的默认),或者不缩进、在段落之间放一道真实的缝(反过来)。混用才造出第一份 LaTeX 文档那种「什么都不齐」的样子,因为文档类的标题、列表和图题全都是按它自带的那一种调好的。

    要用第二种风格,请加载 parskip 宏包而不是手设长度:它给 \parskip 一个伸缩分量,把 \parindent 归零,并重排列表参数以免条目之间的空隙加倍。KOMA-script 的类把这个选择做成选项——parskip=full、parskip=half、parskip=parindent——其中 half 是排版上更讲究的那个,因为它用半个基线距离而不是整行,两端对齐的正文因此不会长得像列车时刻表。

    文档类还会通过它自己的 \@afterheading 机制压掉标题之后第一个段落的缩进。这就是紧接 \section 写的 \noindent 看起来什么都没做的原因,也是要求每段都缩进的美式文档要加载 indentfirst 的原因。想在一行开头强行拿到一份缩进,用显式的 \indent。

    决定做一次,就带出两个习惯。别用 \hspace{1cm} 或一串手敲的空格来开头一个段落——缩进是归文档类管的长度。也别用一行空行去伪造两个段落之间更大的缝:这道缝如果是结构性的,它就该是一个标题或一个列表;如果是排版性的,它就归寄存器管。

    \documentclass[12pt]{article}
    \usepackage[T1]{fontenc}
    \usepackage{lmodern}
    \usepackage{parskip}       % blank-line paragraphs: no indent, real gap
    \usepackage{enumitem}
    \usepackage{needspace}
    
    \setlength{\emergencystretch}{2em}  % last-resort stretching, not first resort
    \hyphenpenalty=150                % make hyphenation a bit more attractive
    \tolerance=1500                   % before emergency stretch is tried
    
    \begin{document}
    
    \section{Space that is not yours to add}
    
    % Wrong, and silent: vertical glue placed in the middle of a line.
    This paragraph tries \vspace{20pt} to push its own second half down the page
    and achieves nothing, because the glue is only obeyed between lines.
    
    \medskip
    \needspace{6\baselineskip}
    A short block that must not be split by a page break: \verb|needspace| asks
    for six lines of room right here and starts a new page if they are not
    available. It is the honest version of the six backslash-backslash pairs
    people type instead.
    
    \section*{And space that the class already owns}
    
    \begin{itemize}[noitemsep,topsep=6pt]
      \item \texttt{parskip} turned the vertical gap between paragraphs on and
            took the indentation off; that is one decision, made once.
      \item It also re-tuned the list parameters, which is why these two items
            sit closer together than the two paragraphs above.
    \end{itemize}
    
    \end{document}

    把页面读回来:间距不对时该查什么

    由外向里查。先问:是整篇文档不对,还是一行不对?整篇的问题都是寄存器问题:\parskip、\baselineskip(也就是 \linespread{factor}\selectfont 或 \setstretch)、列表参数、公式间距——全在导言区或由宏包设定,永不手写。一行的问题是内容问题:一个长词、一个缺失的断词点、一条 URL、一段只能用 \linebreak 而不是 \\ 打断的数学。

    第二,按出现顺序读日志里的 Overfull 与 Underfull,因为前面一次强制换行会改变同一页下游所有行的断法。日志会把出问题的材料夹在两条 | 之间打印,好让你定位它;而最快的诊断是加 draft 类选项编一次:它在每条超宽行上画一道黑条,并把插图换成占位框,于是页面自己指向问题所在。

    第三,记住标准类的默认竖排模式:article 以不齐末行收尾,而 report 与 book 会把短页的文字拉开,让最后一条基线落在每页的同一高度。某一章最后一页间距可疑地松散,那是 \flushbottom 在做事,开关是 \raggedbottom——那是一个版面决定,不是间距 bug,也正是下一课的主题。

    本页的三份清单就是这套工具的源码形态:第一份逐行对比段落换行与强制换行,第二份展示由宏包负责的段落样式与 needspace、emergency stretch 如何共处,第三份是合法用法的短目次——一个表行、一段 aligned 推导、一处手工放的断词、一串塌缩的空格,以及一个把换行抹掉的百分号。

    a\,b \quad a\:b \quad a\;b \quad a\quad b \quad a\qquad b \quad a\!b
    a\,b \quad a\:b \quad a\;b \quad a\quad b \quad a\qquad b \quad a\!b
    \documentclass[11pt]{article}
    \usepackage[T1]{fontenc}
    \usepackage{lmodern}
    \usepackage{amsmath}
    \usepackage{microtype}
    
    \begin{document}
    
    % ---- 1. Two paragraphs: what a blank line buys you -----------------
    This is the first paragraph. It continues across source lines because a
    single newline in the file is just another space to TeX.
    
    And this is the second: the blank line above became \par, so this line is
    indented by \parindent and separated from the paragraph above by \parskip.
    
    % ---- 2. Forced breaks: same paragraph, two lines -------------------
    \begin{center}
      A. Student\\
      Room 214, Faculty of Mathematics\\[6pt]
      a.tudent@example.edu
    \end{center}
    
    % ---- 3. Where \\ is a bug ------------------------------------------
    Never write a double backslash to split a paragraph like this, because
    the line ends ragged, no indentation or paragraph glue appears, and the
    sentence after the break is still the same paragraph.
    
    % ---- 4. A \\ next to display maths is never needed -----------------
    The wave equation is written as
    \[
      \frac{\partial^{2} u}{\partial t^{2}} = c^{2}\nabla^{2} u
    \]
    and the display already starts and ends on its own line, so putting a
    forced break before the \verb|\[| only fights the class's display skips.
    
    % ---- 5. Asking instead of forcing ----------------------------------
    This sentence is long enough that TeX would happily hyphenate something in
    it, but here \linebreak I ask for a break at this exact place and the line is
    still stretched to the right margin, which is what a forced break would have
    cost me.
    
    \end{document}

    本课速查

    每节抽一行关键代码:点小节名跳到对应位置,代码一键复制。

    小节 关键代码
    \begin{array}{lll}\text{source} & \text{what it does} & \text{visible effect} \\\hline \texttt{double backslash} & \text{ends the line} & \text{no indent, no parskip} \\ \texttt{blank line} & \text{ends the paragraph} & \text{indent plus a gap} \\ \texttt{\textbackslash linebreak} & \text{asks for a break} & \text{line stays justified}\end{array}
    \begin{aligned} f(x) & = x^{2} + 2x && \text{row one} \\ & = (x+1)^{2} - 1 && \text{row two} \end{aligned}
    \begin{array}{ll}\text{line to line} & \texttt{baselineskip} \\ \text{paragraph to paragraph} & \texttt{parskip} \\ \text{list above and below} & \texttt{topsep} \\ \text{text to equation} & \texttt{abovedisplayskip}\end{array}
    \documentclass[10pt]{article}
    \documentclass[12pt]{article}
    \documentclass[11pt]{article}

    常见错误

    • 用 \\ 分隔段落。你既没有缩进、也没有段落胶,还得到一条不齐的右边界;段落分隔符是空行或者 \par。
    • 用 \\[20pt] 把公式或表格往页面下推。这段空间粘在断点上,页面在此断开时它就静默消失——而真正的问题通常是一块该用 \needspace 的东西,或者是一个浮动体。
    • \end{tabular} 前多一个 \\:它加出一个空行;带可选参数时,加出的是一行纯粹的空间。
    • 忘了 % 还会吃掉换行本身。表格单元格或 \parbox 里行末的 % 通常是解药;行中间的 % 则刚刚把你后面的代码全注释掉了。
    • 想在行中间用 \vspace 加垂直空间:垂直胶只在行与行之间计数,所以先结束段落(\par),或者用 \\[space]。
    • 把 \sloppy 当成 overfull box 的全局解药。它靠让行任意拉伸来消掉警告;\setlength{\emergencystretch}{1em} 针对同一个问题,却不动文档的其余部分。
    • 把 \linebreak 与 \\ 当同义词:前者是一个罚值,行仍保持两端对齐、TeX 还能在别处断词;后者是一条命令,把这行不齐地结束掉。

    关于本课的常见问题

    LaTeX 里空行和双反斜杠有什么区别?
    空行就是 \par:它结束段落,于是下一行拿到段落缩进,以及 \parskip 放在段落之间的那道缝。\ 只结束当前这一行,段落继续:不缩进、没有段落胶,被结束的那行也不做两端对齐。表格里、aligned 数学里、center 块里、诗文里用 \;散文段落之间用空行。
    怎么换行但不另起一个段落?
    在该结束的地方敲 \(双反斜杠);不需要可选的空间参数和星号时用 \newline 也行。如果这段文字是两端对齐的、你希望断得自然一点,优先用 \linebreak[4]:它请求在此断行,同时仍然把那一行铺到右边界。
    怎么加大 LaTeX 段落之间的距离?
    不要一段一段地加。要么一次定下风格——parskip 宏包,或 KOMA-script 类上的 parskip=half——要么接受文档类的默认,并在确实需要视觉停顿的地方放一个标题或一个列表。在两段之间手敲的 \vspace 在文字重排之前一直能用,之后就会在另一页上显得不对。
    为什么 LaTeX 不理我敲进去的空格?
    因为源码里的空格串、制表符和单个换行统统塌缩成一个词间空格,而命令名还会吃掉紧跟其后的空白。要硬放一个空格就敲 \ (控制空格);要把两个词锁在同一行就用 ~ 连起来;要去掉换行会留下的那个空格,就在行末写 %。
    LaTeX 的 overfull hbox 警告怎么修?
    按顺序来:改写句子;允许断词(\hyphenpenalty,或在你要的位置放一个随时的 \-);给 TeX 留一条最后的 \setlength{\emergencystretch}{1em};亲手打断那段长材料;到这一步之后才用 \sloppy 或 sloppypar 环境。URL 和文件名要用 hyperref 的 \url{} 解决,而不是继续加胶。
    为什么节标题下面没有空间?为什么我的整页被拉得很开?
    两个不同的默认值。标准类不会在标题附近放 \parskip 大小的空间——标题自带它自己的上方与下方间距,那是版面决定而不是 bug。一行行被拉得异常开的页面,是 report 或 book 类在用 \flushbottom,它把一章的最后一页撑到满高;\raggedbottom 就把这件事关掉。

    实时演示:直接编辑 LaTeX,立刻看渲染结果

    预览随输入实时更新——不妨故意写坏一次,看看报错长什么样。

    KaTeX 错误
    试一个例子

    继续读

    同一个东西的三个入口:记法本身、讲它的那一课、以及真正用它写东西的一篇文章。