Bookdown PDF输出中的目录之前的章节 [英] Chapter(s) before table of contents in Bookdown PDF output

查看:62
本文介绍了Bookdown PDF输出中的目录之前的章节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让一章出现在Bookdownpdf_book输出中的目录之前(但标题页之后).

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中(我也需要).我不想同时保留同一章的.tex.Rmd版本.

One way to do this is to add the chapter to a .tex file and and link it using before_body:. However, this means the chapter will not appear in gitbook (which I also need). I'd prefer not to keep both a .tex and .Rmd version of the same chapter.

一个理想的解决方案是将该章保存在.Rmd文件中,并将其内容提取到before_body中作为pdf_book.这样,它仍可用于gitbook.尽管我不确定该怎么做,或者是否确实可行?

An ideal solution would be if the chapter could be kept in a .Rmd file, and its contents extracted into the before_body for pdf_book. That way it's still available for gitbook. Though I'm not sure how I might do that, or indeed if it's possible?

有解决方案吗?还是超出了Bookdown灵活性的限制?

Is there a solution? Or is it exceeding the limits of Bookdown's flexibility?

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

Any help would be greatly appreciated, thanks!

推荐答案

一个可以在文档中手动触发ToC创建,从而可以更好地控制其位置.当然,应该禁用自动创建目录表:

One can trigger ToC creation manually in the document, which gives more control over its placement. Of course, automatic table of contents creation should be disabled:

---
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

缺点是,这仅适用于PDF输出,不适用于HTML.

The downside is that this only works with PDF output, not HTML.

这篇关于Bookdown PDF输出中的目录之前的章节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆