R Markdown生成PDF时章节标题上色失效,求原因排查
R Markdown章节标题上色失败的原因及修复
- 核心问题:配置层级错误
header-includes是pdf_document的子配置项,你把它和pdf_document放在了同一层级,导致LaTeX的颜色设置命令根本没被加载到PDF输出流程里。 - 次要语法问题
第一个LaTeX命令-\usepackage{color}的减号与内容间缺少空格,虽不致命,但破坏了YAML列表的语法规范。
修复后的完整代码:
--- title: "number_sections" output: pdf_document: number_sections: yes toc_depth: 4 toc: true header-includes: - \usepackage{color} - \usepackage{sectsty} - \allsectionsfont{\color{red}} --- # Main Section The above section and the ones below should be red ## 2nd Level ### 3rd Level # Second Section ## another section ### yet another #### and the last one please
修改说明:
- 把
header-includes缩进至pdf_document下方,让R Markdown能正确识别这些LaTeX配置 - 统一所有列表项的格式(减号后加空格),保证YAML语法正确
内容的提问来源于stack exchange,提问作者Salvador
相关产品推荐
相关产品推荐

