When I knit
the following test.Rmd
file:
---
title: "test"
output:
bookdown::html_document2:
toc: true
toc_float: TRUE
code_folding: show
---
# heading 1
# heading 2
It produces a toc
:
But when I render it using:
rmarkdown::render('test.Rmd', output_format = "html_document2")
The toc
is missing:
Does anyone know how to include toc
when rendering with bookdown::html_document2
?
thanks
The output format name should be exactly what you specified in the YAML metadata, i.e.,
rmarkdown::render('test.Rmd', output_format = 'bookdown::html_document2')
instead of
rmarkdown::render('test.Rmd', output_format = 'html_document2')
Alternatively (not recommended), you can call the output format function with options:
rmarkdown::render(
'test.Rmd',
output_format = bookdown::html_document2(
list(toc = TRUE, toc_float = TRUE
)
)
or
rmarkdown::render(
'test.Rmd',
output_format = 'bookdown::html_document2',
output_options = list(toc = TRUE, toc_float = TRUE)
)
These alternative methods are unnecessarily more complicated, and also make the document less reproducible (not making use of options specified inside the document), so you are recommended to just use output_format = 'bookdown::html_document2'
and specify output format options in the Rmd document.