更改 bookdown pdf 输出中的 toc_depth 字段

Change toc_depth field in bookdown pdf output

我正在用 bookdown 创建一本 PDF 格式的书,我想在将书转换为 PDF 时更改 toc_depth 字段的编号。这是我的 _output-yml:

bookdown::gitbook:
  css: style.css
  config:
    toc:
      before: |
        <li><a href="./">A Minimal Book Example</a></li>
      after: |
        <li><a href="https://github.com/rstudio/bookdown" target="blank">Published with bookdown</a></li>
      toc_depth: 5
    download: ["pdf", "epub"]
bookdown::pdf_book:
  includes:
    in_header: preamble.tex
  latex_engine: xelatex
  citation_package: natbib
  keep_tex: yes
bookdown::epub_book: default

我添加了 toc_depth: 5 但没有结果。我该怎么做?

在您的示例中,bookdown::gitbook 块中有 toc_depth,它负责 HTML 输出。如果你想要这个用于 PDF 输出,正如你的标题所暗示的,你需要在那里添加它,即

...
bookdown::pdf_book:
  includes:
    in_header: preamble.tex
  latex_engine: xelatex
  citation_package: natbib
  keep_tex: yes
  toc_depth: 5
...

也可以:https://bookdown.org/yihui/rmarkdown/pdf-document.html