Bookdown with more than 3 levels in navigation?

Hello,

I am trying to create a bookdown book and have it show up on github. However, it seems like the navigation of the bookdown book only allows for 3 levels of headers. I would like to be able to add more levels as it's extremely important for the user to be able to quickly navigate from one section to another.

What are some potential solutions to this problem? And are there any solutions in the pipeline before I start building?

  • I have thought about creating a nested book. Basically create a book, and then have a link in one of the pages link to another book that I create. However, there seems to be a couple issues with this. (1) I will end up with 2 index.htmls, and both will be located in the same github location. (2) I don't believe using the search of the outer book will result in results in the inner book.

Are there any other solutions for this or ideas for this? Such as make the base page NOT index.html?

Thanks!

You could try using the (PART) special header (https://bookdown.org/yihui/bookdown/markdown-extensions-by-bookdown.html#special-headers). I haven't used it yet, but I might, soon.

1 Like

I wonder why this limitation of Three levels... It seems like the TOC should show every levels :thinking:

Seems like an expected behaviour and from bookdown books: https://bookdown.org/yihui/bookdown/html.html

The toc option controls the behavior of the table of contents (TOC). You can collapse some items initially when a page is loaded via the collapse option. Its possible values are subsection , section , none (or null ). This option can be helpful if your TOC is very long and has more than three levels of headings: subsection means collapsing all TOC items for subsections (X.X.X), section means those items for sections (X.X) so only the top-level headings are displayed initially, and none means not collapsing any items in the TOC. For those collapsed TOC items, you can toggle their visibility by clicking their parent TOC items. For example, you can click a chapter title in the TOC to show/hide its sections.

Just confirmed that levels 4 and 5 in a test book don't show up at all in the TOC. Perhaps there's another setting?

I can't find one, and it seems odd that they don't show... maybe a bug ?

:man_facepalming:

And I remember now !! You need to use the same parameter as in rmarkdown::html_document, called toc_depth because Pandoc which is generating the toc will default to three levels !!

That means you should add

gitbook:
    toc_depth: 6

in the yaml header !

It is documented in the help page as ... is passed to html_document as explained, and html_document has this option !

Sorry for having forgot this !

2 Likes

Thanks! Sorry I'm a bit new. Does that line of code go into .travis.yml or _bookdown.yml or _output.yml?

Ahh I got it. It needs to be in the RMD of the chapter where you want more than 3 levels. Thanks!

It is meant to go in where you define your gitbook() format so _output.yml or yaml header in index.Rmd.

Thanks! I'll have to take a look again. It was working for a second, and now it's not - even when I put it into _output.yml or index.Rmd. I'll have to spend time debugging when I have more time.

Oh odd... Start in a clean new session, and take care of the indentation in the yaml and where you put the field (inside gitbook parameters).