I am numbering sections and specifying table of contents depth using the following in the yaml
header:
output:
html_document:
toc: yes
toc_depth: 3
number_sections: true
toc_float:
collapsed: false
code_folding: hide
theme: cerulean
For sections that are automatically numbered, I'm getting depth 4 sections (#### ....
) numbered. How can I specify the depth limit for section numbering? I know how to suppress numbering using #### .... {-}
but would enjoy having something more automatic.
I am not aware of any other built in solution. And I think that the effort needed to add {-}
is not that high.
Anyways, you could add this chunk at the beginning of your document:
```{r, results='asis', echo = F}
toc_depth <- rmarkdown::metadata$output$html_document$toc_depth
sel <- paste0("h",(toc_depth+1):10, collapse = " > span, ")
cat(paste0("<style>",
sel,
" > .header-section-number { display: none; } </style>"))
```
It reads out the toc_depth
YAML option and then prints some lines of CSS to simply hide all elements of class .header-section-number
that belong to a heading greater than toc_depth
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With