阶段 4 · 结构与交叉引用 28 / 48 ≈ 12 分钟读完

LaTeX 脚注与边注:合法位置、编号方式与 marginpar

脚注不是一段文字,而是一台两部件的机器:行里的一个标记,加页面底部的一处插入,由一个计数器把它们粘在一起。这就是为什么有些地方收得下、有些地方会安静地把它吃掉。这一课覆盖合法位置、表格与浮动体里的标记/正文配对、编号的每一条路子,以及页边这一替代品。

    一条脚注是两个对象,不是一个

    TeX 遇到 \footnote{text} 时会做两件互不相干的事。在当前行里它印一个标记:计数器 footnote 步进,\thefootnote 经 \@makefnmark 作为上标排出。而往页面里它放一处插入:注释正文连同脚注线一起进入 \footins 这个插入寄存器,输出例程稍后把它接到 \textheight 下面、交给 \@makefntext。

    脚注一切古怪之处都出自这道裂缝。标记落在你敲下的位置;正文落在页面结束的位置。任何会搬动材料的东西——浮动体、分栏、双栏版面、一个 minipage——都能把两半分开;而任何会重读源码的东西(目录、页眉、图目录)都可能把标记再排一次、把计数重复一遍。

    值得记住的几个尺寸全是普通长度:\skip\footins 是最后一行正文到脚注线之间的垂直空间,\footnotesep 是分隔两条注的支撑高度,而注本身经 \@makefntext 按 \footnotesize 排。如果你的脚注挤在正文最后一行上,改 \setlength{\skip\footins}{14pt} 就是修的地方。如果它们爬进了下版心,那是这一页已经没有位置、插入正在被拆开——这就引到下文的 footmisc 包及其 bottom 选项。

    \underbrace{\text{mark}}_{\text{in the line}} \quad \longmapsto \quad \underbrace{\text{text}}_{\text{below the rule}}
    \underbrace{\text{mark}}_{\text{in the line}} \quad \longmapsto \quad \underbrace{\text{text}}_{\text{below the rule}}

    脚注不能放在哪些地方,以及该改写成什么

    有四个地方是禁区,而且各有各的坏法。移动参数——\section、\caption、\chapter、\item 的可选参数——会被写进辅助文件并重新排版,于是那里的一条注按去向各计一次:经典结果是一个错编号,外加 hyperref 的一条 Footnote ... is multiply defined 警告。浮动体与 tabular 单元格会打断标记与正文的配对,因为浮动体可能落在另一页上。逐字材料里根本容不下任何命令。而脚注里再套脚注是插入的嵌套,TeX 不支持。

    标题里的正确配方是三件套:给目录一个短形式、正文里放长形式、注前面加 \protect——\section[Short title]{Long title\protect\footnote{...}}。\protect 阻止这条注在标题被写出去时展开,于是注的正文排在标题出现的那一页、绝不会出现在目录里。如果你只需要给标题或作者挂一条注,用 \thanks{}:它把材料收集进 \@thanks、用一套自己的符号序号排在题头下方,与 footnote 计数器无关。

    表格里的答案是你自己把脚注拆开。\footnotemark 印标记并步进计数器;\footnotetext 用计数器当前的值印正文。把标记放进 tabular、关掉浮动体,然后把计数器往回走,让正文一条条对上:\addtocounter{footnote}{-1}\footnotetext{first note}\stepcounter{footnote}\footnotetext{second note}。这是一笔台账,跨多次编辑很脆弱,所以表格注释长期来看更稳的办法是 threeparttable 和它的 tablenotes 列表:注成为表格盒子的一部分,于是跟着它一起浮动。

    还有两处陷阱,不看到输出是发现不了的。p{<width>} 列是一个 minipage,所以里面的 \footnote 完全合法、却落在单元格下面,用独立的 mpfootnote 计数器按字母编号——读者会把这当作排版错误。而 longtable 某行末尾的 \footnote 可能对每个页面片段各排一次;那些注要连标记/正文配对一起挪到环境之后。

    Where footnote text lands: page foot, bottom of a minipage, or nowhere inside a float 1. PLAIN TEXT - THE DOCUMENTED CASE ... the claim.\footnote{note} 1 skip\footins 1 note text, footnotesize, below the footnote rule mark and text are both produced by one \footnote call, in the same page stream. 2. MINIPAGE OR p{} CELL \begin{tabular}{p{4cm}p{4cm}} a footnote rule of the box a note text, here - not on the page A p{} column is a minipage: the counter is mpfootnote, the marks are letters, the text is clipped to the box - readers call it a bug. 3. FLOAT OR l/c/r TABLE CELL \begin{table}[htbp] ... \end{table} the float travels to another page; the mark goes with it, the insertion does not: text is lost, or the counter advances twice \footnotemark in the cell \addtocounter{footnote}{-1} \footnotetext{note} after the float two halves, deliberately separated In a table the note must be written as a pair; for notes that belong to the table itself, use threeparttable tablenotes instead. The rule behind all three pictures A footnote is a mark placed in the line and a text placed in an insertion. Anything that moves material (float, box, column) or re-reads the source (table of contents, list of tables, running head) separates the two - so write those notes as an explicit mark/text pair.
    同一行源码,按标记站的位置不同,会产出页面底部的一条注、盒子底部的一条注,或者一条永远不会出现的注。
    \documentclass[a4paper,11pt]{article}
    
    \usepackage[T1]{fontenc}
    \usepackage{amsmath}
    \usepackage{booktabs}
    \usepackage[a4paper,margin=2.5cm]{geometry}
    
    \begin{document}
    \section{Two ways to footnote a table}
    
    % --- (1) marks inside the tabular, texts after the float -------------
    % A \footnote inside a table would be swallowed by the float machinery, so
    % the mark and the text are written as two halves of one operation.
    \begin{table}[htbp]
      \centering
      \begin{tabular}{llr}
        \toprule
        Symbol & Quantity & Value \\
        \midrule
        $\alpha$ & fine structure    & $7.297\times10^{-3}$\footnotemark \\
        $c$      & speed of light    & $299\,792\,458$\footnotemark \\
        \bottomrule
      \end{tabular}
      \caption{Constants with two marks.}\label{tab:constants}
    \end{table}
    % \footnotemark has already advanced the counter twice; walk it back to the
    % first mark, print that text, then step forward for the second.
    \addtocounter{footnote}{-1}%
    \footnotetext{Dimensionless, and measured.}%
    \stepcounter{footnote}%
    \footnotetext{Exact, since the metre was defined from it.}
    
    % --- (2) the p{} column trap ----------------------------------------
    % A p{} column is a minipage, so \footnote inside one does NOT go to the
    % bottom of the page: it is printed under the cell, with the independent
    % minipage counter (letters).
    \begin{center}
    \begin{tabular}{p{4.5cm}p{4.5cm}}
      \hline
      This cell carries a note.\footnote{Read this one under the cell, marked
      with a letter, not at the foot of the page.} &
      And this one is plain text. \\
      \hline
    \end{tabular}
    \end{center}
    
    For tables whose notes must travel with the table, the environment to reach for
    is \verb|threeparttable| with its \verb|tablenotes| list and \verb|\tnote{a}|
    marks; for notes that belong at the foot of the page, use the mark/text pair above.
    
    A note in ordinary text, for contrast.\footnote{This one really does sit at the
    bottom of the page.}
    \end{document}

    编号:符号、字母、每页、每节

    那个号码不是写死的——它是 \thefootnote 展开成什么就是什么,所以整套标记的外观离你只差一个 \renewcommand。真正要用的四种设置:\arabic{footnote}(默认)、要安静学者气的 \roman{footnote}、给表格用的 \alph{footnote},以及扉页那条不编号的致谢注所用的 \fnsymbol{footnote} 序列。把 \thefootnote 排成空,就得到匿名脚注,评注式行文要的就是这个。

    \fnsymbol 值得一段,因为它是唯一不把计数器当数字用的那个。内核定义是一个九分支的开关:星号、双剑号、ddagger、节号、段落号、双竖线,然后是加倍形式 **、††、‡‡。第十次请求不会绕回——它掉进 \@ctrerr,以 Counter too large 停下。这个上限正是为什么这种风格用在扉页致谢上:那里只有一两条注、也不需要编号;也正是为什么全局切到它却不同时按页重启计数器,是一场慢动作事故。另外请注意 hyperref 为目标名另存了一个 Hfootnote 计数器,而 \setcounter{footnote}{0} 不会复位它,所以手工重启编号的文档里,正文中一个 * 的反向引用可能标着七。

    复位点本身也是计数器。按页重编号在内核里不是一个文档类选项:要加载 \usepackage[perpage]{footmisc}。按节重编号才是通用机制:\counterwithin{footnote}{section}(内核命令;旧安装上来自 chngcntr 包)。按页重编号加 bottom 是多数图书文档类采用的组合,而 footmisc 除这两个之外值得知道的键有 bottom(把注钉在版心底部,不让它们在短页下往上飘)、norule、ragged,以及 flushmargin(把标记挂进版心,而不是缩进首行)。

    {}^{\ast},\ {}^{\dagger},\ {}^{\ddagger},\ {}^{\S},\ {}^{\P},\ {}^{\|},\ {}^{\ast\ast},\ {}^{\dagger\dagger},\ {}^{\ddagger\ddagger}
    {}^{\ast},\ {}^{\dagger},\ {}^{\ddagger},\ {}^{\S},\ {}^{\P},\ {}^{\|},\ {}^{\ast\ast},\ {}^{\dagger\dagger},\ {}^{\ddagger\ddagger}
    \documentclass[12pt,a4paper]{article}
    
    \usepackage[T1]{fontenc}
    \usepackage[utf8]{inputenc}
    \usepackage{amsmath}
    \usepackage[a4paper,margin=2.5cm,bottom=3.2cm]{geometry}
    \usepackage[bottom,perpage,flushmargin]{footmisc}
            % bottom    : push the footnotes to the very bottom of the page
            % perpage   : restart the numbering on every page
            % flushmargin: hang the mark into the margin instead of indenting
    
    \setlength{\skip\footins}{16pt}   % gap between the text and the footnote rule
    \setlength{\footnotesep}{9pt}    % gap between two footnote texts
    
    \title{Notes on notes\thanks{Collected in the title block, marked with symbols.}}
    \author{A. Student}
    
    \begin{document}
    \maketitle
    
    % --- three ways to write the number ---------------------------------
    \renewcommand{\thefootnote}{\arabic{footnote}}  % 1, 2, 3   (the default)
    % \renewcommand{\thefootnote}{\roman{footnote}}   % i, ii, iii
    % \renewcommand{\thefootnote}{\fnsymbol{footnote}} % *, dagger, ddagger, S, P
    % \renewcommand{\thefootnote}{}                   % unmarked notes
    
    The Euler product is due to Euler.\footnote{First note on this page.}
    A second claim, a second note.\footnote{Second note.}
    A third one reuses the first mark---\footref{1} \verb|\footref| is supplied by
    \texttt{footmisc}, and it repeats a mark without spending a new number.
    
    \section[A short heading for the TOC]{A long heading\protect\footnote{A note in
    a heading is set on the page the heading lands on, never in the table of
    contents.}}
    Because \verb|\section| writes its title to the table of contents, the note had
    to be protected, and the heading needed a short optional form.
    
    \subsection*{Zeroing the counter by hand}
    \setcounter{footnote}{0}
    After the reset the next note is number one again.\footnote{Numbered from one.}
    \end{document}

    独立公式里的脚注

    独立公式是一个自带水平列表的组,所以里面的 \footnote 会落在不可预测的位置——多半是标记排在那条公式之后,看着没问题,直到公式跨页;又或者标记出现在居中版式的左边缘。两个稳的位置是:紧接闭合的 \] 之后(让标记挂在标点上,这正是读者预期的),或者在包含该公式那句话的句末。

    当你确实希望标记坐在数学内部的某个符号上,别在那里用 \footnote;改用数学外部的上标:标记用 \footnotemark 放在符号之后、正文用 \footnotetext 放在这条 display 之后。同样的手法在正文模式里更通用:x\footnotemark[3] 印出第三条注的标记而不碰计数器,正文另写。请注意两种语法的差别——\footnotemark[3] 把编号作为可选参数,\footnotetext[3]{...} 对正文做同样的事。

    amsmath 的 \intertext 与 \intertext* 在这里值得一提,但理由不同:它们是对齐组内部仅有的、可以合法放普通文字(因而也可以放脚注)的位置。修饰整段推导的注属于它前面那句话,修饰单个符号的注属于最后一行上挂着的 \text{...}——而不是对齐环境内部。

    \sum_{k=0}^{\infty} c_{k}x^{k} = f(x)^{\,\dagger}
    \sum_{k=0}^{\infty} c_{k}x^{k} = f(x)^{\,\dagger}
    演示区里那个双剑号是把 \dagger 当上标用,而这正是 \fnsymbol{footnote} 画一页第二条注的方式。

    边注:marginpar 做了什么你没料到的事

    \marginpar{text} 比它看上去更老也更脆。它并不在你写下的那个位置上进入版心:TeX 记下这条注、把它附到它出现的那一行,输出例程再把盒子放进外侧版心——oneside 与 twoside 的奇数页在一侧、偶数页在另一侧。如果这个盒子会和版心里已有的一条重叠,LaTeX 就把后到的那条往下推 \marginparpush;这一页再放不下,它就挪到下一页并警告 Marginpar on page ... moved。盒子对页码机制也是隐形的,所以一条乱跑的 \marginpar 看起来像是被忽略了,其实它只是旅行了。

    管着这一栏的三个长度是 \marginparwidth(盒子的宽度;在标准文档类里它在 11pt 与 12pt 下小得离谱,这正是「我的边注没法读」这个抱怨的来源)、\marginparsep(正文与注之间的水槽)和 \marginparpush(两条注之间的最小垂直间隔)。用 geometry 时前两个直接设——marginparwidth=2.6cm, marginparsep=8pt——而你必须确认你的纸面真有那么多外侧版心,否则注就排进了可打印区域。内容的样式走 marginnote 包里的 \marginfont,或者 memoir 里类自带的 \@margincaption。

    \marginpar 也有和 \footnote 一样的移动参数问题,还多一条:它不能出现在浮动体、\begin{minipage} 或另一个盒子里,因为这条注是插入到页面流里的、不是插入到盒子里的。所以脚注那一课的教训在这里换一套语法重演了一遍,而替代者就是下面要点名的那个包。

    Page geometry of the margin column: textwidth, marginparsep, marginparwidth and the vertical push between two notes TWOSIDE SPREAD - NOTES GO TO THE OUTER MARGIN even page (left-hand) note text printed in the left margin the line that carried \marginpar \textwidth marginparwidth odd page (right-hand) note text same box, outer side this time marginparbox is set with its own font: \marginfont, and inside the box \raggedright is customary marginparsep marginparwidth VERTICAL BEHAVIOUR note A, anchored to its line note B marginparpush - the minimum gap; if it does not fit, the note moves down, then to the next page, and the log says "Marginpar on page ... moved" \marginpar: a page insertion, box and float material refused \marginnote: anchored to the line, optional vertical offset, usable inside floats, never migrates to the next page
    版心、水槽、边注盒:marginpar 落在外侧版心、与它所在行同高的位置,marginnote 则允许你手动推那个高度。
    \documentclass[11pt,twoside]{article}
    
    \usepackage[T1]{fontenc}
    \usepackage{amsmath}
    \usepackage[a4paper,top=2.5cm,bottom=2.8cm,left=3.5cm,right=3.5cm,
                marginparwidth=2.6cm,marginparsep=8pt]{geometry}
    \usepackage{marginnote}
    \usepackage{graphicx}
    
    % The box width is \marginparwidth, the gutter is \marginparsep, and the
    % minimum vertical gap between two notes is \marginparpush - all three are set
    % above through geometry. Style the content of the box with \marginfont:
    \renewcommand{\marginfont}{\scriptsize\raggedright\itshape}
    
    \begin{document}
    \section{Margin material}
    
    A sentence that needs an aside.\marginpar{A \texttt{\string\marginpar} note: it
    is anchored to the line it sits in, and if there is no room it is pushed down
    the margin --- or onto the next page, with a warning.}
    The rule is that \verb|\marginpar| places its box in the \emph{outer} margin of
    a two-sided document, using the vertical position of the line that carried it.
    
    \subsection*{Why marginnote exists}
    The same anchor problem is solved differently by the \texttt{marginnote}
    package: the note is positioned against the current line, it never changes the
    page number, and --- crucially --- it can be used where \verb|\marginpar|
    cannot, such as inside a float or in the caption area.
    \marginnote{This note is set with \texttt{\string\marginnote}, and the optional
    second argument nudges it vertically.}[-2.5ex]
    
    \begin{figure}[htbp]
      \centering
      \setlength{\fboxsep}{22pt}
      \fbox{\parbox{5cm}{\centering a figure}}
      \caption{A float carrying a margin note.}
      \marginnote{A \texttt{\string\marginpar} here would be lost or would trigger
      ``marginpar on page moved''; inside a float, use \texttt{\string\marginnote}.}
    \end{figure}
    
    Two vertical offsets show the difference between the two commands: the first
    note above is tied to the paragraph, the second is tied to the line it was
    written on.\marginpar{Second \texttt{\string\marginpar}.}
    \end{document}

    marginnote,以及一条注什么时候其实是边栏小标题

    marginnote 包提供同样的视觉对象,却有三处实际差别。\marginnote{text} 把注排在当前行上、永远不会把它挪到下一页;可选的第二参数接受一个垂直偏移,所以 \marginnote{...}[-2.5ex] 能把盒子往上拉、去和某个标题对齐;而且它在 \marginpar 被拒的地方——浮动体和装盒材料里——照样能用。在标准文档类里给出类似 \marginline 行为的也是这个包,而它的 \marginfont 钩子就是文档化的那条设样式的路。

    代价是多一趟编译和一点台账:marginnote 会保存锚点信息,好让偏移量在正确的页上解析,所以一份从未编译过两遍的文档,可能把某条注显示在离它那一行差一页的地方。而且既然它不再是页面插入,一段很长的边栏文字就没有跨页拆分的机制——如果你的边栏材料长到这份上,它就不是注、而是第二栏,干那活的工具是 mpar 式的文档类(memoir、Tufte 风格模板),或者一个带固定窄列的双列 tabular。

    动手之前先决定你在用哪一种装置。脚注强迫读者离开句子、往下看、再找回位置:它适合只有 5% 的读者会想看的那类插话。边注把眼睛留在正文栏里:适合注解、出处,或你希望与段落同读的连续评注。第三种选择是经 endnotes 包做的尾注,它把所有内容搬到文末一个清单里,适合法律或档案类的注疏装置——那里的注长到足以毁掉版面。

    x^{a},\ y^{b},\ z^{c} \qquad (\text{a separate counter})
    x^{a},\ y^{b},\ z^{c} \qquad (\text{a separate counter})

    版面、分页,以及那些消失的注

    不管你喜不喜欢,脚注都参与分页。插入是一只必须放在正文之下的盒子,所以一条长注会从页面上抢走正文行数,而放不下的注会被 \footins 的罚分拆开。如果你看到正文被往上抽、下面留出一大块空,那就是插入正在被安置。几个旋钮:\interfootnotelinepenalty(调高可以阻止单条注跨页拆分,代价是更多空白)、\bottomnumber(被拆的注有多少留在第一页),以及 footmisc 的 bottom 选项,它阻止注在短页下往上爬。

    那个看起来像 bug 的失败模式,是一条注压根不出现。它几乎总是四件事之一:p{} 型 tabular 单元格里的注(它印在了单元格下面)、浮动体里的注(被浮动体自己的盒子吞了)、\parbox 或 minipage 里的注(又是那个 minipage 计数器),或者移动参数里的注被排在你没去看的地方,例如图目录。把日志打出来搜 Footnote 与 marginpar:这两类麻烦都会留下痕迹。

    最后两个让长文档保持清醒的习惯。给一条会被引用两次的注在内部打上 \label{fn:sources},之后用 \autoref{fn:sources} 或 \footref 重新指过去,而不是把它重写一遍;永远不要手工编注号——你一旦在文件更前面插入一条,下游每个写死的数字都错了,这和定理环境里反对手写编号是同一条论证。

    本课速查

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

    小节 关键代码
    \underbrace{\text{mark}}_{\text{in the line}} \quad \longmapsto \quad \underbrace{\text{text}}_{\text{below the rule}}
    \documentclass[a4paper,11pt]{article}
    \documentclass[12pt,a4paper]{article}
    \sum_{k=0}^{\infty} c_{k}x^{k} = f(x)^{\,\dagger}
    \documentclass[11pt,twoside]{article}
    x^{a},\ y^{b},\ z^{c} \qquad (\text{a separate counter})

    常见错误

    • 把 \footnote 直接写进 tabular 单元格。在 l/c/r 列里这条注可能丢掉、也可能落在错误的地方;单元格里用 \footnotemark、浮动体之后用 \footnotetext,或者把表格换成 threeparttable。
    • 写 \section{Title\footnote{...}},既不给短的可选形式也不加 \protect。LaTeX 会为目录把标题重排一次,脚注计数器前进两格,hyperref 报一条重复定义的脚注。
    • 用了 \fnsymbol{footnote} 却在一页里写十条注:内核那个开关只有九个分支,第十条掉到 Counter too large,编译会停下而不会把清单重播一遍。请按页重启计数器,或者这么多注干脆保留数字。
    • 把 \marginpar 当成一个「可以随便放东西的非浮动区」。它在 minipage、parbox 或浮动体里拒绝工作,边栏排满时还会迁移到下一页——日志里只留一句警告。
    • 用 geometry 设页边距,却让 \marginparwidth 停在标准文档类的默认值;结果注印在一个 1.5cm 宽、还关掉了连字的盒子里,无法阅读。
    • 指望 p{...} 列里的注出现在页面底部。那是一个 minipage,注会带着自己的字母计数器排在单元格下面;确实需要落到页脚的话,请用标记/正文配对把文字搬出去。

    关于本课的常见问题

    LaTeX 表格里怎么放脚注?
    单元格里用 \footnotemark、表格环境之后用 \footnotetext,因为完整的 \footnote 写在浮动体里位置不可靠。\footnotemark 已经前进过计数器,所以第一条 \footnotetext 之前要用 \addtocounter{footnote}{-1} 退回去,其余各条之间用 \stepcounter。如果注属于表格而不是页面,请用 threeparttable 与 tablenotes。
    脚注怎么不用数字、改用符号?
    导言区一行:\renewcommand{\thefootnote}{\fnsymbol{footnote}}。这就切到星号、双剑号、ddagger、节号、段落号那个序列,也是单条致谢注的传统风格。想让它重新从头开始就先 \setcounter{footnote}{0},另外记住这个表只有九项,用完不会绕回。
    我的脚注怎么不见了?
    它多半在一个会改变去向的地方:p{} 列或 minipage 会把注排在那个盒子底部并按字母编号,浮动体可能整个吞掉它,移动参数则可能把它排进目录而不是正文。先在日志里搜 Footnote 与 Marginpar 警告,再把标记和正文两半分开写。
    marginpar 和 marginnote 有什么区别?
    两者都写进边栏这一列。\marginpar 是内核命令:它锚在自己出现的那一行,边栏满了就被往下推或挪到下一页,并且在盒子或浮动体里拒绝工作。\marginnote 来自 marginnote 包:它贴着当前行定位、接受一个可选的第二参数作垂直偏移、能在浮动体里用,也让你用 \marginfont 重设盒子的样式。
    脚注能不能按页重新编号?
    能,但不是从内核来:加载 \usepackage[perpage]{footmisc}。再加 bottom 把注留在版心底部、加 flushmargin 把标记挂进边栏。若要按节编号,请用通用机制 \counterwithin{footnote}{section}。
    同一条脚注想引用第二次怎么办?
    用 footmisc 包提供的 \footref{编号},它把已有的标记再印一次而不消耗新编号。另外 \footnotemark[n] 与 \footnotetext[n]{...} 都把编号作为可选参数,所以这套配对也能完全由你自己驱动。

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

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

    KaTeX 错误
    试一个例子

    继续读

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