虽然我们可以通过在YAML标题中添加选项number_sections: true
来自动化数字部分,但我想知道我们是否可以更改r markdown
中的标题样式。例如,我们可以使用下面的字母来定制它吗?
:一种。 A节
A.1小节
A.1.1小节1
A.1.2小节1
B中。 B节
B.1小节
B.1.1子小节
答案 0 :(得分:1)
pdf_document
将此行保存在外部文件中(例如inheader.tex
):
\renewcommand{\thesection}{\Alph{section}}
并将文件插入文档的标题中:
---
title: "Lettered sections"
output:
pdf_document:
number_sections: true
includes:
in_header: inheader.tex
---
html_document
格式编织此Rmd
文件:
---
title: "Lettered sections"
output: html_document
---
```{css, echo=FALSE}
.header-section-number {
display: none;
}
body {
counter-reset: counter-level-1;
}
h1:not(.title) {
counter-increment: counter-level-1;
counter-reset: counter-level-2;
}
h1:not(.title)::before{
content: counter(counter-level-1, upper-alpha) ". ";
}
h2 {
counter-increment: counter-level-2;
counter-reset: counter-level-3;
}
h2::before {
content: counter(counter-level-1, upper-alpha) "." counter(counter-level-2) " ";
}
h3 {
counter-increment: counter-level-3;
}
h3::before {
content: counter(counter-level-1, upper-alpha) "." counter(counter-level-2) "." counter(counter-level-3) " ";
}
```
# Section
## Subsection
### Sub subsection
### Sub subsection
## Subsection
# Section
## Subsection
### Sub subsection
## Subsection
<强>说明强>
数字部分是原生pandoc
选项。似乎pandoc
没有为分层标题定制提供任何支持。
因此,HTML输出有三个选项:
pandoc
并开发一个新作家,因为等级标题被声明为整数see here, line #105。请注意,relevant recent issue为了便于标题自定义。 toc: true
。此答案提供了使用CSS自定义分层标题的示例。建议将所有CSS代码(即第7至39行)保存到扩展名为.css
的外部文件中,并使用此YAML标头将其包含在HTML报告中:
---
title: "Lettered sections"
output:
html_document:
css: "filename.css"
---
附加说明
可以使用除数字或字母之外的其他计数器,请参阅here以获取列表
您还可以使用@counter-style
定义自己的一组计数器。