Home > Net >  Why does toc_depth doesn't work with rmarkdown theme?
Why does toc_depth doesn't work with rmarkdown theme?

Time:12-29

I want to create a Rmarkdown html report with the downcute (chaos) theme from the package rmdformats. Now everything works except for the toc_depth argument in my yaml header. The table of contents will only show h1 and h2's.

install.packages("rmdformats")
---
title: "Title"
date: "`r format(Sys.time(), '%d %B, %Y')`"
output:
  rmdformats::downcute:
    code_folding: hide
    toc_depth: 5
    self_contained: true
    thumbnails: false
    lightbox: true
    downcute_theme: "chaos"
pkgdown:
  as_is: true
---

# h1

## h2

### h3

#### h4

##### h5

CodePudding user response:

Unfortunately rmdformats::downcute() only works with toc_depth 2 or less out of the box. There are plenty of issues on rmdformats GitHub page where this is discussed for different themes.

However, based on one answer for this issue, you can get toc_depth: 5 by pasting this into the start of your R Markdown file:

<style>
#toc ul.nav li ul li {
    display: none;
    max-height: none;
}

#toc ul.nav li.active ul li  {
    display: block;
    max-height: none;
}

#toc ul.nav li ul li ul li {
    max-height: none;
    display: none !important;
}

#toc ul.nav li ul li.active ul li {
    max-height: none;
    display: block !important;
}
</style>

Note that this will ruin the smooth animation of the toc.

  • Related