Quarto文档PDF输出:为附录编号加字母并重启编号
在Quarto PDF中实现附录章节/图表编号重启
要让附录章节从A开始编号、子章节用A.1/A.2格式,同时按需重置图表编号,直接用LaTeX命令修改计数器和编号规则即可,具体操作如下:
完整示例代码
--- title: "Test" format: pdf: number-sections: true number-depth: 4 editor: visual --- # Section 1 Text # Section 2 Text ::: {=latex} \appendix \setcounter{section}{0} \renewcommand{\thesection}{\Alph{section}} \renewcommand{\thesubsection}{\thesection.\arabic{subsection}} % 如需重置图表编号,取消下方注释 % \setcounter{figure}{0} % \setcounter{table}{0} % \renewcommand{\thefigure}{\thesection.\arabic{figure}} % \renewcommand{\thetable}{\thesection.\arabic{table}} ::: # First Appendix ## More Results Text ## Even More Results Text
关键代码解释
\appendix:标记附录开始,触发LaTeX的附录模式\setcounter{section}{0}:把章节计数器重置为0,确保附录从A开始计数\renewcommand{\thesection}{\Alph{section}}:将章节编号格式改为大写字母(A、B、C...)\renewcommand{\thesubsection}{\thesection.\arabic{subsection}}:定义子章节编号为「字母.阿拉伯数字」格式- 若要重置图表编号,取消注释对应的代码块,图表会跟随附录章节编号(如A.1、A.2)
这样导出PDF后,章节标题就会完全符合你的期望:
- Section 1
- Section 2
- A. First Appendix
- A.1 More Results
- A.2 Even More Results
内容的提问来源于stack exchange,提问作者Ryan Baxter-King
相关产品推荐
相关产品推荐

