简体   繁体   English

如何指定初始级别以将我的目录扩展到 R bookdown 项目(gitbook 输出格式)? 使用 YAML 设置?

[英]How can I specific the initial level to have my table of contents be expanded to in an R bookdown project (gitbook output format)? With YAML setting?

I have a large bookdown project with a table of contents that I have set to use 4 levels of headings, which it does fine but starts out expanded ( see first edit, this is not accurate ).我有一个包含目录的大型 bookdown 项目,我已将其设置为使用 4 级标题,它做得很好,但开始时扩展了(请参阅第一次编辑,这不准确)。 I want it collapsed to start.我希望它崩溃开始。 I specified the table of contents depth in _output.yml :我在_output.yml 中指定了目录深度:

bookdown::gitbook:
  toc_depth: 4

A sample .Rmd file could have the following headings for its sections.示例 .Rmd 文件的部分可能具有以下标题。 I also included my YAML header which produces the gitbook output format):我还包含了我的 YAML 标头,它生成了 gitbook 输出格式):

---
site: bookdown::bookdown_site
output: bookdown::gitbook
---

# Any Given Programming Language
## Overview
### Variables
### Data Types
#### int
#### double
#### String
#### bool
...

The problem I have with the default behavior is that, say, I want to select "Data Types" from above.我对默认行为的问题是,比如说,我想从上面选择“数据类型”。 When I do, it collapses the list it contains (int, double, etc.), where I would rather it just show me the section headers by default.当我这样做时,它会折叠它包含的列表(int、double 等),我宁愿它默认只显示部分标题。 That way I could click the header, taking me to the start of the section, and it would let me link to any subsections (instead of having to click "Data Types" again to open this list).这样我就可以单击标题,将我带到该部分的开头,它可以让我链接到任何子部分(而不必再次单击“数据类型”来打开此列表)。

I do not know if this is even an option, but if not it really should be.我不知道这是否是一种选择,但如果不是,它真的应该是。 I am not a fan of the default.我不是默认的粉丝。

Even better would be if I could specify a level to expand to by default, aka at ## or ### instead of #### (the default in my example).更好的是,如果我可以指定默认扩展到的级别,也就是 ## 或 ### 而不是 ####(我的示例中的默认设置)。 But my initial question is that currently my toc depth is 4 and it expands to that, and I'd be happy if it just started collapsed to depth 1 (# My Book Titles ).但我最初的问题是,目前我的 toc 深度是 4,它会扩展到那个深度,如果它刚开始折叠到深度 1(# My Book Titles ),我会很高兴。

Edit: I'm wrong about it starting out fully expanded, not sure why I thought that (maybe it had saved state).编辑:我错了它开始完全扩展,不知道为什么我这么想(也许它已经保存了状态)。 It starts out expanded at the 2nd level headings (##), but when you click one of those it expands both the 3rd (###) and 4th (####) all at once.它从第 2 级标题 (##) 开始展开,但是当您单击其中一个标题时,它会同时展开第 3 (###) 和第 4 (####) 个标题。 When I click the 3rd heading to jump to the start of the section, it collapses the 4th headings (see Data Types clicked discussion above).当我单击第 3 个标题跳转到该部分的开头时,它会折叠第 4 个标题(请参阅上面单击的数据类型讨论)。 I'd still prefer it just expand the next level down, so that I can click that heading then see what it contains, or be able to set the default level of the table of contents to show.我仍然希望它只是向下扩展下一级,以便我可以单击该标题然后查看它包含的内容,或者能够设置要显示的目录的默认级别。 The gitbook output just seems kinda glitchy. gitbook 输出似乎有点小故障。 Don't even get me started on the search bar...甚至不要让我开始在搜索栏上...


With the solution I accepted, your _output.yml file should have this:使用我接受的解决方案,您的 _output.yml 文件应该具有以下内容:

bookdown::gitbook:
  toc_depth: 4
  config:
    toc:
      collapse: section (or subsection, or subsubsection)

The toc still behaves strangely in my opinion but this was helpful.在我看来,toc 的行为仍然很奇怪,但这很有帮助。

Another edit: subsubsection expands all levels of headings on load, but you cannot collapse any levels when you click a heading later - I liked that behavior.另一个编辑: subsubsection 在加载时扩展所有级别的标题,但是以后单击标题时无法折叠任何级别- 我喜欢这种行为。

Use de collapse setting.使用折叠设置。

toc:
  collapse: section

And for other levels collapse: subsection, collapse: subsubsection, ...对于其他级别collapse: subsection, collapse: subsubsection, ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM