Distill格式R Markdown文档目录(TOC)配置不生效问题咨询
问题原因
你的目录无法生成的核心原因是YAML配置的参数层级错误:distill格式的专属渲染参数(包括TOC、代码折叠、章节编号等)必须嵌套在output字段下的distill::distill_article子节点中,你当前把这些参数直接写在YAML根层级,distill格式无法识别,因此没有生成目录。
普通html_document格式的配置参数可以直接放在YAML根层级,但distill格式不遵循这个规则,所有渲染相关配置必须归属到对应输出格式的子配置项中。
修复后的正确YAML配置
--- title: Evidence for Resilient Agriculture ERA description: | Using tidymodels to Explore Agroforestry Data date: "7/23/2021" author: - first_name: "Kamau" last_name: "Lindhardt" url: https://www.linkedin.com/in/magnus-kamau-lindhardt/ affiliation: World Agroforestry Centre, Nairobi affiliation_url: https://www.worldagroforestry.org - name: "Peter Steward" bibliography: library.bib csl: frontiers-in-ecology-and-the-environment.csl output: distill::distill_article: toc: true toc_float: collapsed: false smooth_scroll: true number_sections: true toc_depth: 3 code_folding: true ---
修改后重新渲染文档即可正常生成目录,你现有文档里的多级标题结构符合TOC提取要求,无需额外调整。
内容的提问来源于stack exchange,提问作者Kamau Lindhardt
相关产品推荐
相关产品推荐

