阶段 6 · 出版、宏与宏包 46 / 48 ≈ 14 分钟读完

LaTeX book 文档类:部、章、前置页与双面版心

book 类替你做好的其实是一小批决定:允许哪几级分节、每一级从纸面的哪儿起、编号在哪些点重启、四条边里由谁来承担书脊。把这些决定读出来,学位论文就不再是从模板里继承下来的一堆代码——每一条你都可以带着意图去改它。

    四个文档类共用一个内核,每个选项动的又是哪一处

    article、report、book、letter 是从 base 发行里同一个源文件解包出来的,分节机制完全共用,差的只是几处默认值。看得见的差别是:\chapter 只在 book 和 report 里存在,\part 同样只此两家,而 \frontmatter、\mainmatter、\backmatter 是 book 独有。所以交稿时把 report 换成 book 不是在挑样式,而是在声明两件事:章的编号归谁管,以及这份稿子是否按双面印刷来排。

    默认值讲的是同一个故事。book 自己带上 twoside 与 openright,页面家具从 \pagestyle{headings} 起步;report 是 oneside 配 \pagestyle{plain},页眉那条带要你自己去开;article 压根没有章这一级,页码落在页脚。哪天你发现自己在用某个类手工复刻另一个类的行为,那就是选错了类。

    交稿前真正拨得动东西的选项是这些:字号 10pt、11pt、12pt(base 类只给这三档,再要细只能靠 KOMA-Script 的 fontsize=12.5pt)、纸型 a4paper 或 letterpaper、单双面 oneside/twoside、起页规则 openright/openany、扉页 titlepage/notitlepage、公式位置 fleqn 与编号位置 leqno,最后是 draft/final。它们每一个都只是把类内部某个开关拨一下,而这些开关在 \documentclass 那一行被读一次就定了型;稿子隔了一层包装文件时,还能伸进去的那只手叫 \PassOptionsToClass。

    两条常被当作退路的家系值得先认识。KOMA-Script 的 scrbook 把上面这些全部做成有文档可查的选项,外加 \addchap 与 \addsec,专管「不编号但要登记进目录」的分节;memoir 则把章样式、页眉、题注、书目条目这些宏包的活儿收进同一个类,接口是一个 \chapterstyle{header}。判断一份大学模板写得有多勉强,看它是不是 book 外加四十行 \makeatletter 补丁就够了——那四十行通常是在手工重做 memoir。

    \textstyle \sum_{n=1}^{\infty} \frac{1}{n^{2}} = \frac{\pi^{2}}{6} \qquad \displaystyle \lim_{N\to\infty} \sum_{n=1}^{N} \frac{1}{n^{2}}
    \textstyle \sum_{n=1}^{\infty} \frac{1}{n^{2}} = \frac{\pi^{2}}{6} \qquad \displaystyle \lim_{N\to\infty} \sum_{n=1}^{N} \frac{1}{n^{2}}

    frontmatter、mainmatter、backmatter 实际拨动的开关

    这三个命令的定义值得直接去类文件里看,因为流传的说法错得很具体。\frontmatter 展开是三行:先 \cleardoublepage,再 \@mainmatterfalse,最后 \pagenumbering{roman}。\mainmatter 形状相同:\cleardoublepage、\@mainmattertrue、\pagenumbering{arabic}。\backmatter 只做一个带条件的翻页加上一个 \@mainmatterfalse,页码编号碰都不碰。

    账很清楚:三个里两个会重启页码计数器,三个全都挪动 \if@mainmatter,没有一个改页面样式。常被复述的「前置部分用 plain、正文用 headings」恰好说反了——book 只装一次 headings、全文共享,这就是目录页顶着一条页眉的原因;要它安静,得自己写 \thispagestyle{empty},或者整段换回 \pagestyle{plain}。

    \if@mainmatter 的作用面比想象里窄,也最容易看漏:在 \@chapter 内部,它只管三件事——\refstepcounter{chapter} 走不走、给日志的那句 \typeout 写不写、目录条目要不要带 \numberline。于是后置部分里的一句 \chapter 照样进目录、照样设自己的标记,只是没有号码。索引和参考书目要的正是这个行为;可如果你希望附录的章仍带字母编号,那得靠 \appendix。

    重启编号带来的另一个后果要等出事才看得见:同一份 PDF 里会有两张都印着 1 的页,一张罗马一张阿拉伯。凡是拿印刷页码当键的机制都可能因此指错页,切过好几轮 \pagenumbering 的论文里链接落到隔壁页并不稀奇。粗暴的解法是 hypertexnames=false;省事的解法是把 \frontmatter 写在 \maketitle 之后而不是之前。

    Timeline of a book: front matter with roman numbers, main matter restarting at arabic 1, back matter, and where the recto and blank verso pages fall \frontmatter · \pagenumbering{roman} · NO CHAPTER NUMBERS title page \thispagestyle{empty} unnumbered and uncounted in practice contents i–iii \tableofcontents plus \listoffigures, \listoftables, preface blank iv verso left by \cleardoublepage THE ONLY TWO THINGS \mainmatter CHANGES: NUMBERING STYLE AND \@mainmatter \mainmatter = \cleardoublepage + \@mainmattertrue + \pagenumbering{arabic} Part I · page 1 \part → \thispagestyle{empty} part page is a recto; \@endpart adds a blank Chapter 1 · page 3 \chapter → \thispagestyle{plain} openright forces the recto; \@topnum=0 so no float lands chapters 2 … n · running arabic \ps@headings: even page = author/titles, odd page = marks set by \chaptermark, page numbers in the outer corners backmatter · arabic continues, chapters unnumbered \backmatter = \if@openright\cleardoublepage\else\clearpage\fi + \@mainmatterfalse ← no \pagenumbering here appendices, bibliography, index: \chapter still enters the TOC, without a number What does NOT switch: the page style book sets \pagestyle{headings} once, in the class — \frontmatter leaves it alone, so your contents pages get running heads unless you ask otherwise: \addtocontents{toc}{\protect\thispagestyle{empty}} · \pagestyle{plain} inside front matter Number restarts are why a thesis needs care with hyperref: two pages can both be “1”. If links jump to the wrong one, hypertexnames=false makes anchor names count occurrences instead of reusing numbers.
    前置部分走罗马数字,正文部分从阿拉伯 1 另起,后置部分只换编号开关——而页面样式是三个命令谁都没动的那一件。

    part 与 chapter,以及各自从哪一页开始

    \chapter 的头三步是固定的:\if@openright\cleardoublepage\else\clearpage\fi,接着 \thispagestyle{plain},然后 \global\@topnum\z@。让人耗掉一整个下午的通常是第三步:类在章首页的顶部禁止放浮动体,于是紧跟 \chapter 的那张图会一路漂到下一页。出路有两条现成的——\afterpage{\clearpage},或者给浮动体写死 [ht];第三条是接受它,印刷书本来就这么排。

    题名那块盒子出自 \@makechapterhead:\vspace*{50\p@} 起头,一行 \huge\bfseries 排 \@chapapp\space\thechapter,接 \vskip 20\p@,题名本身用 \Huge\bfseries,收尾 \vskip 40\p@;全程套着 \interlinepenalty\@M,再长的题名也不会被拆成两截。整套东西包在一个 \raggedright、\parindent\z@ 的组里,最后交棒给 \@afterheading——章题之后首段不缩进,就是它干的。

    \part 在更高的那一级:它独占一页,那一页还是 \thispagestyle{empty};双面加上 openright 时,类会用 \@endpart 再补一张空白背页。那张纸不是故障,也不在印刷页数里算浪费——它是左右页纪律的一部分。真希望 part 随处起页,选项叫 openany,只是它连带把章的起页规则也一起改了。

    \appendix 是开关不是分节命令:它把 \@chapapp 换成 \appendixname,把 \thechapter 换成 \Alph{chapter},往后的 \chapter 于是排成附录 A、B、C 并各自续编。该放的位置要看清:正文区里。要是塞到 \backmatter 之后,那里的章本来就不编号,附录字母会静悄悄消失。

    \int_{\Omega} \nabla u \cdot \nabla v\,\mathrm{d}x = \int_{\partial\Omega} v\,\frac{\partial u}{\partial n}\,\mathrm{d}s
    \int_{\Omega} \nabla u \cdot \nabla v\,\mathrm{d}x = \int_{\partial\Omega} v\,\frac{\partial u}{\partial n}\,\mathrm{d}s
    The vertical anatomy of a book chapter opening page as the kernel builds it, with each skip labelled HOW \chapter BUILDES THE OPENING PAGE (\@MAKECHAPTERHEAD, BOOK CLASS) \vspace*{50\p@} — the star matters: without it TeX drops glue at the top of a page Chapter 4 ← \huge\bfseries \@chapapp\space\thechapter \vskip 20\p@ after \par\nobreak Boundary Value Problems ← \Huge\bfseries #2 \vskip 40\p@ then \noindent text follows first paragraph: \raggedright, \parindent=0pt inside the heading group, \@afterindentfalse + \@afterheading suppress the indent of the paragraph after the title \ps@plain puts the page number in the footer here \global\@topnum\z@ → no float at the top so a figure you placed first drifts to the next page 50pt 20pt 40pt THE FOUR WAYS TO RESTYLE IT, IN ORDER OF PAIN 1 · \renewcommand{\chaptername}{Part} · \renewcommand{\thechapter}{\Roman{chapter}} names and counters only — no layout touched, safe in any class 2 · titlesec: \titleformat{\chapter}[display]{\Huge}{Chapter \thechapter}{20pt}{} declares the shape instead of copying kernel code; \titlespacing sets the skips 3 · \makeatletter \def\@makechapterhead#1{…} \makeatother works, and breaks silently for a class you did not read — memoir and KOMA exist so you do not have to in memoir: \chapterstyle{header}; in scrbook: \addchap plus titlestyle options
    内核搭出来的章首页:三段跳空、两档字号,外加一条顶部不许有浮动体的规矩。

    include、includeonly,还有那对自带的翻页

    \include{ch2} 不是名字好听一点的 \input。它会先翻页——开着 openright 时一直翻到一张右页——往主 .aux 里写一行 \@input{ch2.aux},读那个文件,读完再翻一次页。这一对翻页保证了一个章的浮动体不会溜进下一个章,也解释了它为什么比想象中慢:每个章的结尾都要把积压的浮动体清账清干净。

    排版惯例由此而来:一章一个文件,比章小的单位一律 \input。内核明确拒绝 \include 套 \include,所以章文件里再去 \include 一节属于错误;\input 则能随便嵌套,也不附加任何翻页。

    正因为每个被 \include 的文件握着自家那份 .aux,\includeonly{ch2,ch5} 才谈得上是一次不撒谎的局部构建:被跳过的章仍会被读到足以保留旧标签、旧计数器和旧目录条目的程度,于是章号和每一个 \ref 都与全量构建保持一致。这就是「在写第五章」和「在写另一份文档」的分界——后者是 subfiles 与 standalone 实际给你的东西,代价是编号从此和整本书对不上。

    两种翻车法。一个文件被 \include 过又改了名,主 .aux 里那句 \@input 就悬着了,于是每趟编译都要替你问一遍文件去哪儿了;处理办法是把 .aux 删干净,或者让 latexmk -C 去删。另一件:\bibliography 或 \printbibliography 属于最后一个 \include 之后的后置页,别塞进某个可能被局部构建跳过的章文件里。

    How include differs from input: forced page breaks, one aux file per chapter and the includeonly subset that keeps numbering intact WHAT \include{ch2} EXPANDS TO, IN ORDER \clearpage flushes every pending float \cleardoublepage if openright: + a blank verso \write\@mainaux{\@input {ch2.aux}} ← the hook \input{ch2} your text, verbatim \clearpage again after the file SO THE PROJECT LAYOUT FOLLOWS FROM THE MECHANISM thesis.tex \includeonly{ch2,ch5} comment out for a full build \frontmatter \maketitle \tableofcontents \mainmatter \include{ch1} \include{ch2} … \include{ch9} \backmatter \include{biblio} \printindex \includeonly still reads ch1 and ch3 to the end, so \chapter numbers,\tdot labels and the TOC stay identical — only the pages stop being typeset what sits in the aux files thesis.aux → \@input{ch1.aux} … \@input{ch9.aux} ch2.aux → \newlabel{eq:bc}, \citation{...}, \chapter{...} TOC lines, \@writefile a chapter you leave out with \includeonly keeps its OLD .aux, so its labels resolve as before — that is exactly why partial builds do not scramble cross-references the way \input truncation does FOUR THINGS THAT BIT EVERYONE HERE 1 · \include inside \include is refused (the kernel nests one level only); \input for sub-parts of a chapter, and it adds no page break of its own. 2 · The forced \clearpage is why a chapter that ends with a figure never lets that figure wander into the next chapter — and why \include costs you float-cycling time on a big thesis. 3 · Deleting .aux files to “fix a reference” throws away every chapter’s stored labels at once; \includeonly with a stale .aux is the opposite failure — a number you cannot reproduce. latexmk -C is the clean restart.
    一次 include、一对翻页、一份 aux:局部构建之所以安全,机制全在这三样上。

    双面版式:inner 与 outer、书脊那一英寸、页眉的那条带

    base 类里没有一个字叫「页边距」,它设的是 \oddsidemargin 和 \evensidemargin,而 TeX 会额外再从纸边算走一英寸没人写在文档里的偏移。book 在 10pt 下这两个值是 .5in 与 1.5in,11pt、12pt 下是 .25in 与 1.25in——正好差一英寸的那部分是书脊,所以书的内侧天生比外侧宽。\textwidth 在 10pt 是 4.5in,再往上取 5in,而 \textheight 按基线行数计、不用英寸。

    同一批数字也解释了关于这个类最常见的那句抱怨:版心不够宽。五列的 bmatrix 塞进 6in 版心的 article 里刚刚好,落到 5in 就溢出。可行的处理是把 display 拆行、只给这条公式单独降字号、或者有意把版心放宽;唯一不该做的是让 Overfull \hbox 往外侧长出去——那一截会在装订时被裁掉。

    换上 geometry 之后就不必再想那两个寄存器了:双面文档里 inner 与 outer 对应奇偶两侧的边距,物理余量单独交给 bindingoffset,剩下的由 hcentering 或 marginpar 收尾。这个宏包要加载在类之后,否则参数覆盖不赢;而且 twoside 也得一并传进去,因为这个宏包对边距的奇偶有自己的主张。

    headheight 是另一条经典坑:base 类给的是 12pt,比一条真实页眉需要的盒子矮,于是 fancyhdr 每页印一句 headheight is too small 直到你动手为止。诚实的修法是 \setlength{\headheight}{14pt},同时从 \topmargin 里扣掉同样多;不要拿 \raggedbottom 去遮,也不要假装没看见。双面书稿里的边注默认走外侧,因为 \@mparswitch 是开的,想反过来自有 \reversemarginpar。

    R_{\mathrm{ext}} = \frac{1}{4\pi\varepsilon_{0}} \sum_{k=1}^{n} \frac{q_k}{\lvert \mathbf{r} - \mathbf{r}_k \lvert} \ne \mathrm{finite\ size}
    R_{\mathrm{ext}} = \frac{1}{4\pi\varepsilon_{0}} \sum_{k=1}^{n} \frac{q_k}{\lvert \mathbf{r} - \mathbf{r}_k \lvert} \ne \mathrm{finite\ size}

    目录与各类清单,以及页眉那几个字是从哪儿来的

    目录文件是排到哪儿写到哪儿:每个分节命令都会调一次 \addcontentsline{toc}{chapter}{…},每个浮动体调一次 \addcontentsline{lof}{figure}{…}。谁能进到最终那张清单,由两个计数器把关:tocdepth(book 里一般拨到 1 只留章,或 2 到节)与 secnumdepth(决定谁配不配有号)。两条彼此独立,所以「有号却不列」和「列了却没号」都成立,后者正是 \chapter* 配一句手写的 \addcontentsline 造出来的东西。

    「要一条不编号却出现在目录里的章」,标准答案就是这一对:\chapter*{Notes on notation}\addcontentsline{toc}{chapter}{Notes on notation}。KOMA 把两行缩写成 \addchap{…}。若条目丢了页码或者没有点线,真正要打的靶子是存进去那行里的 \protect\numberline{};想整张清单换一副面孔,交给 titletoc 或 tocloft,别去做内核手术。

    自定义清单是同一台机器换个扩展名。在 \chapter*{List of Symbols} 里放一个 \@starttoc{sym},条目用 \addcontentsline{sym}{symbol}{…} 写出去,你就有了一份符号表——方案表、缩略语表同理——而且它和目录一样能安然穿过 \include:分章 .aux 先各自收,主 .aux 再把它们汇拢。两头都要包在 \makeatletter 里,因为这些帮手的名字里带 @。

    页眉走的是另一条管道,跟目录不通。页面样式 headings 读 \leftmark 与 \rightmark,这两个值来自 \markboth 和 \markright,而落笔写标记的活儿由分节命令经 \chaptermark、\sectionmark 完成。所以页眉印的不是标题本身,而是这两个宏被定义成什么就印什么:整页大写要改 \chaptermark 才算治到根上;每章头一页页眉不对位,则是因为 TeX 设标记是异步的、总慢一页。

    % 放在 preamble。改的是 book.cls 已经定义好的东西,所以要有 \makeatletter。
    \makeatletter
    
    % --- 1. chapter name and number format: no layout touched
    \renewcommand{\chaptername}{Part chapter}
    \renewcommand{\thechapter}{\Roman{chapter}}
    \renewcommand{\@chapapp}{\chaptername}       % the word printed above the title
    
    % --- 2. a quieter chapter opening than the kernel default
    \def\@makechapterhead#1{%
      {\parindent\z@\raggedright\normalfont
       \vspace*{24\p@}%
       \Large\bfseries\@chapapp\space\thechapter\par\nobreak
       \vskip 6\p@
       \huge\bfseries #1\par\nobreak
       \vskip 30\p@
       \rule{3cm}{0.4pt}\par}%
    }
    % unnumbered chapters (\chapter*) go through \@schapter, style it too:
    \def\@schapter#1{\if@twocolumn\@topnewpage[\@makeschapterhead{#1}]%
      \else\@makeschapterhead{#1}\@afterheading\fi}
    
    % --- 3. stop \chapter from forcing a right-hand start (or keep it)
    \PassOptionsToClass{openany}{book}
    
    % --- 4. running heads come from marks set by the sectioning commands
    \renewcommand{\chaptermark}[1]{\markboth{\thechapter.\ #1}{}}
    \renewcommand{\sectionmark}[1]{\markright{\thesection.\ #1}}
    \makeatother
    
    % --- 5. headers need the room; 12pt default headheight triggers a warning
    \setlength{\headheight}{14pt}
    \addtolength{\topmargin}{-2pt}

    扉页,以及前置部分剩下的那套机械

    带默认 titlepage 选项的 book 里,\maketitle 就是一个 titlepage 环境:拿 \@title、\@author、\@date 拼出一页,写一句 \thispagestyle{empty},末尾来一个 \cleardoublepage。多位作者之间由 \and 分开,\thanks{} 产出那条带 dagger 的注,\dedication{} 给你一页献词。这些值过后还能从 \thetitle 与 \theauthor 取回——半标题页和页眉要复用标题,靠这个,而不是把它再敲一遍。

    类没提供的那些页——丛书页、写着 ISBN 与版次的版权页、印一句印刷说明的空白背页——别去和 \maketitle 较劲,自己用 titlepage 环境,一页一个,每页配一句 \thispagestyle{empty}。本页第三段示例源码走的就是这条路,而前置部分仍是罗马数字,因为 \frontmatter 已经在它们前面跑过了。

    前置页的顺序之争,一个问题就能了断:哪一页必须落在右页?章必须,part 必须,扉页应当。剩下的——版权声明是压在半标题页的背面还是挪到扉页之后——是社内规矩,但它会改变总页数,因为每一句 \cleardoublepage 都可能塞进一张空白。排错了,评审会撞见一章从左页开始;排对了,没有人会注意到这件事。

    最后几件事不归文档类管,但还是要一并交代:PDF 大纲要的是 hyperref 的选项,\hypersetup{pdftitle=…, pdfauthor=…} 直接吃 \thetitle 就够了;那份 .ind 索引由 imakeidx 或 makeidx 生成、把 \printindex 落在后置页;参考书目自成一段。这些在本站都各有一页,而归 book 类的只有一件——决定它落在哪一段页里,因为它的页码和目录条目长相全由此而来。

    \documentclass[11pt,a4paper,twoside]{book}
    \usepackage{tikz}
    \usepackage{hyperref}
    
    \makeatletter
    % ---- a hand-built title page: book's \maketitle is a titlepage environment
    \renewcommand{\maketitle}{%
      \begin{titlepage}%
        \thispagestyle{empty}%
        \null\vfil\begingroup
          \raggedright\Huge\bfseries\@title\par\vskip2em
          {\Large\@author\par}
          \vfill
          {\large\@date\par}
        \endgroup\vfil\end{titlepage}%
    }
    
    % ---- a custom list: register the extension, then write to it
    \newcommand{\listofsymbols}{%
      \chapter*{List of Symbols}%
      \@starttoc{sym}%
    }
    \newcommand{\sym}[2]{%
      \addcontentsline{sym}{symbol}{\textbf{#1}\hfill #2}%
    }
    \makeatother
    
    \begin{document}
    
    \frontmatter
    
    % half title: a recto with one line on it, deliberately unnumbered-looking
    \begin{titlepage}\thispagestyle{empty}\vspace*{2cm}
      \begin{center}\huge Series in Applied Analysis \# 12\end{center}
    \end{titlepage}
    
    % verso of the half title: the copyright / impression statement
    \clearpage\thispagestyle{empty}
    \small
    Boundary Value Problems. First edition, 2026.\\
    Printed on acid-free paper. All rights reserved.
    
    \cleardoublepage
    \maketitle
    
    \dedication{For my advisers.}
    
    \tableofcontents
    \listofsymbols
    
    \mainmatter
    \chapter{Existence}\label{ch:ex}
    Let $\sym{L^{2}(\Omega)}{square-integrable functions on $\Omega$}$ and
    $\sym{\nabla u}{the weak gradient}$ be as usual.  The symbol list above was
    written by \texttt{\string\sym}, not by hand.
    
    \addcontentsline{toc}{chapter}{Notes on notation}
    \chapter*{Notes on notation}
    An unnumbered chapter that still appears in the contents: the pair of lines
    above is the whole trick.
    
    \end{document}

    本课速查

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

    小节 关键代码
    \textstyle \sum_{n=1}^{\infty} \frac{1}{n^{2}} = \frac{\pi^{2}}{6} \qquad \displaystyle \lim_{N\to\infty} \sum_{n=1}^{N} \frac{1}{n^{2}}
    \int_{\Omega} \nabla u \cdot \nabla v\,\mathrm{d}x = \int_{\partial\Omega} v\,\frac{\partial u}{\partial n}\,\mathrm{d}s
    R_{\mathrm{ext}} = \frac{1}{4\pi\varepsilon_{0}} \sum_{k=1}^{n} \frac{q_k}{\lvert \mathbf{r} - \mathbf{r}_k \lvert} \ne \mathrm{finite\ size}
    \documentclass[11pt,a4paper,twoside]{book}

    常见错误

    • 指望 \frontmatter 顺手把页面样式也改了。它只管编号和 \if@mainmatter;book 会让 headings 一路留在目录页上,直到你自己写 \pagestyle{plain} 或逐页把它压掉。
    • 把 \appendix 放到 \backmatter 之后:后置部分里章是不编号的,于是「附录 A」静静退化成一个连字母都没有的标题。
    • 在被 \include 进去的文件里再写一次 \include——内核只给一层。凡比章小的单位,请一律改用 \input。
    • 改了名或删掉某个章文件,却把 \@input{…} 留在主 .aux 里,结果每趟编译都冒一次文件缺失的提示。别猜,直接清 aux。
    • 把 headheight is too small 当耳旁风。它不是噪音——分给页眉的那条带会被悄悄压矮。设 \headheight,再从 \topmargin 里减掉同样多。
    • 写了 \chapter*{Title} 又纳闷它怎么不进目录:星号形式从来不会写目录行。补一句 \addcontentsline{toc}{chapter}{Title},或者用 KOMA 的 \addchap。
    • 让一张图浮到了下一个章里去:这是类的手笔不是你的错——\chapter 会设 \@topnum\z@,章题之上不允许有浮动体。要么搬走浮动体,要么有意断一页。
    • geometry 的边距照 \oddsidemargin 的老思路写,然后奇怪双面稿的偶数页怎么歪了:请给 inner 与 outer,并把 twoside 一并传给宏包。

    关于本课的常见问题

    book 类里的 \frontmatter 究竟做了什么?
    三件事:先 \cleardoublepage,让前置部分从右页起头;再 \@mainmatterfalse,从此章不再编号;最后 \pagenumbering{roman},页码以小写罗马数字重新从 i 开始。页面样式它一个字都不改,意外多半出在这里。\mainmatter 是它的镜像,只是编号换成了阿拉伯数字;\backmatter 则只翻一次页、关掉章编号,让阿拉伯序列继续往下走。
    学位论文该用 book 还是 report?
    会被双面印刷就选 book:它默认 twoside 与 openright,页眉开箱即用,内侧边距也天然替书脊留了宽度。只交一份单面 PDF 就选 report:章的编号逻辑更直白,页面样式默认是 plain。\chapter 和 \part 两边都有,\frontmatter、\mainmatter、\backmatter 只有 book 有——这正是 report 模板只能手写 \pagenumbering 去假装前置页的原因。
    怎样让章不再每张右页起头?
    给类传 openany:\documentclass[twoside,openany]{book}。内核于是改用 \clearpage 而不是 \cleardoublepage,不再插入空白背页。学校若规定章必须起于右页,openright 就得留着;写作期间嫌翻页多,宁可用 \includeonly 收窄构建范围,也别动这个选项——openany 一改,全文每一处翻页都跟着变。
    不编号的章怎么让它进目录?
    那一行自己补:\chapter*{Bibliography} 之后接 \addcontentsline{toc}{chapter}{Bibliography}。星号压掉的是编号,不是目录条目,两者本来就各走各的。KOMA-Script 里同一件事写作 \addchap{...},memoir 里是不编号的章命令配一句 \addcontentsline。要是条目连数字格式都丢了,该查的是存进辅助文件的那句 \protect\numberline,而不是你的 \chapter 调用。
    book、report、memoir 的实质差别在哪?
    book 与 report 是同一份内核代码配两套默认:章和 part 两家都有,book 默认 twoside 加 headings、report 默认 oneside 加 plain,三个 matter 命令只在 book 里。memoir 是另一种设计——章样式、页眉、题注、脚注、扉页、目录这些宏包被吸进一个有文档的接口,\chapterstyle{header} 一行就抵得上二十行 @ 命令补丁。KOMA-Script 的 scrbook 坐在两者中间,是迁移成本最低的那条路。
    为什么同一份 PDF 里页码 1 出现了两次?
    这是设计如此:\frontmatter 把前置部分编成 i、ii、iii,\mainmatter 再从阿拉伯 1 起算,印刷书向来这样。它给 PDF 添的麻烦是两张页共享一个印出来的数字,凡以这个数字为键的机制——包括一部分链接与书签——都可能挑到错的那一页;hyperref 的 hypertexnames=false 让锚点名按出现次序编号,不再信任印刷值。

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

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

    KaTeX 错误
    试一个例子

    继续读

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