Chapter(s) before table of contents in Bookdown PDF output

pyg*_*pyg 3 pandoc knitr r-markdown bookdown

I'd like for a chapter to appear before the table of contents (but after the title page) in the pdf_book output of Bookdown.

一种方法是将章节添加到.tex文件中并使用before_body:. 但是,这意味着该章节将不会出现gitbook(我也需要)。我不想同时保留同一章的a.tex.Rmdversion。

理想的解决方案是将章节保存在.Rmd文件中,并将其内容提取到before_bodyfor 中pdf_book。这样它仍然可以用于gitbook. 虽然我不确定我该怎么做,或者确实可能吗?

有解决办法吗?还是超出了Bookdown的灵活性极限?

任何帮助将不胜感激,谢谢!

tar*_*leb 6

可以在文档中手动触发 ToC 创建,这样可以更好地控制其位置。当然,应该禁用自动目录创建:

---
title: "MWE"
output:
  bookdown::pdf_book:
    toc: False
---

```{r child = 'file-you-want-to-include.Rmd'}
```

```{=latex}
% Trigger ToC creation in LaTeX
\tableofcontents
```

# Rest of your document starts here
Run Code Online (Sandbox Code Playgroud)

缺点是这只适用于 PDF 输出,不适用于 HTML。