如何在Quarto RevealJS幻灯片中调整章节标题计数器?
解决Quarto幻灯片跨文档标题编号问题
要实现每个独立文档对应一级编号(如文档1为1.x,文档2为2.x),文档内的#作为二级编号、##作为三级编号的效果,需要正确组合shift-heading-level-by和number-offset两个参数,具体设置如下:
单个文档的YAML配置
第一个文档(对应一级编号1)
在文档开头的YAML块中添加:
--- format: revealjs # 替换为你使用的幻灯片格式(如beamer) number-sections: true shift-heading-level-by: 1 number-offset: [0] ---
number-sections: true:开启标题编号功能shift-heading-level-by: 1:将文档内所有标题的层级提升1级——原本的#(一级标题)变为二级标题,##变为三级标题number-offset: [0]:设置一级标题的编号偏移为0,即一级编号从1开始,因此文档内的二级标题会以1.1、1.2开头,三级标题为1.1.1
第二个文档(对应一级编号2)
修改number-offset参数即可:
--- format: revealjs number-sections: true shift-heading-level-by: 1 number-offset: [1] ---
number-offset: [1]:一级标题编号偏移1,即从2开始,文档内的二级标题会以2.1、2.2开头,三级标题为2.1.1
后续文档
以此类推,第N个文档的number-offset设置为[N-1]即可。
效果验证
以第一个文档为例,输入内容:
# First part of the document This should be part 1.1 ## First section/slide This should be numbered as 1.1.1 # Second part of the document This should be part 1.2 ## First section/slide of the second part This should be numbered as 1.2.1
渲染后,#标题会显示为1.1 First part of the document,##标题显示为1.1.1 First section/slide,完全符合预期。
内容的提问来源于stack exchange,提问作者Michael
相关产品推荐
相关产品推荐

