How can I have a toc_float in a R bookdown document?

Viewed 1161

I've been working on a report in r-markdown that is getting a bit lengthy and want to break it up into parts with bookdown. I'm using a custom html template with a bootstrap menu bar that is enabled in yaml front-matter with:

toc: true
toc_float: true

My reproducible example produces the following error:

Error in html_document(fig_width = fig_width, fig_height = fig_height, : You must use a theme when specifying the 'toc_float' option Calls: ... -> base_format -> output_format -> html_document

and when I include theme: default I get this error:

Error in html_document(fig_width = fig_width, fig_height = fig_height, : formal argument "theme" matched by multiple actual arguments Calls: ... do.call -> -> base_format -> output_format

The document knits without toc_float, but my bootstrap menu bar disappears (as it was designed to do).

Any ideas?

Parent doc:

---
title: "test doc"
output:
  bookdown::html_document2:
    # theme: default
    base_format: rmarkdown::html_vignette
    toc: true
    toc_float: true

---

```{r child = "chapters/01-child.Rmd"}
```

Child doc:

#  Child

Child
1 Answers

If I understand this correctly, toc_float does not work with rmarkdown::html_vignette as you cannot set a theme.

From the documentation of rmarkdown::html_vignette:

Additional arguments passed to html_document. Please note that theme, fig_retina and highlight are hard coded. Setting any of those will yield an error. [...]

Compared to html_document, it:

  • never uses retina figures
  • never uses a theme

However, a possible solution might be to switch from html_vignette to html_document:

output:
  html_document:
    toc: true
    toc_depth: 3
    toc_float: true
Related