简体   繁体   English

如何从knitr rmarkdown PDF中分离标题页和目录页?

[英]How to separate Title Page and Table of Content Page from knitr rmarkdown PDF?

Anyone have any idea how to separate Title Page and Table of Content page?有人知道如何分隔标题页和目录页吗? From this code:从这段代码:

---
title: "Title Page"
output: 
  pdf_document:
      toc: true
      number_sections: true
---

The few line of code above creates the Title and Table of Content, but there is no separation between the Title Cover Page and Table of Content.上面的几行代码创建了标题和目录,但标题封面和目录之间没有分离。

I have found an alternative by adding latex symbols \newpage and \tableofcontents :我通过添加 latex 符号\newpage newpage 和\tableofcontents找到了替代方案:

---
title: "Title Page"
output: 
    pdf_document
---

\centering
\raggedright
\newpage
\tableofcontents

# header 1
```{r}
summary(cars)
```

## header 2
```{r, echo=FALSE}
plot(cars)
```

## header 3
lore ipsum 

# header 4
lore ipsum

Is there a way without having to use latex \newpage and \tableofcontents and use rmarkdown somewhere in the following block:有没有办法不必使用 latex \newpage newpage 和\tableofcontents并在以下块中的某处使用rmarkdown

---
title: "Title Page"
output: 
    pdf_document:
        toc: true
---

I used a trifecta of latex files in the options under includes: 我在下面的选项中使用了三个乳胶文件includes:

---
title: "Title Page"
output: 
  pdf_document:
  toc: true
    number_sections: true
  includes:
    in_header: latex/header.tex
    before_body: latex/before_body.tex
    after_body: latex/after_body.tex
---

The before_body file contain all of the options you would want AFTER the \\begin{document} and the title options, but BEFORE you start writing the body of your document. before_body文件包含\\begin{document}和title选项之后你想要的所有选项,但是在你开始编写文档正文之前。 In that file, simply place a \\newline , like so: 在该文件中,只需放置\\newline ,如下所示:

\newpage

That's it! 而已! Nothing else in the before_body.tex file. before_body.tex文件中没有其他内容。 That should work. 这应该工作。

Now, if only I could vertically center the title page... 现在,如果只有我可以垂直居中标题页...

To avoid messing with tex files,为了避免弄乱tex文件,

Turn off automatic toc insertion first in the YAML metadata.首先在 YAML 元数据中关闭自动 toc 插入。

---
title: "myTitle"
date: "`r Sys.Date()`"
output: 
  pdf_document:
    toc: no
    number_sections: true
urlcolor: blue
editor_options:
  chunk_output_type: console
documentclass: report
---

Then, wherever you want the toc to be in your document, add然后,无论您希望目录位于文档中的哪个位置,添加

```
{=latex}
\setcounter{tocdepth}{4}
\tableofcontents
```

You can then place this toc anywhere using latex macros such as \newpage or \hfill\break for example.然后,您可以使用 latex 宏(例如\newpage newpage 或\hfill\break )将此目录放置在任何位置。

---
title: "myTitle"
date: "`r Sys.Date()`"
output: 
  pdf_document:
    toc: no
    number_sections: true
urlcolor: blue
editor_options:
  chunk_output_type: console
---
\newpage
```{=latex}
\setcounter{tocdepth}{4}
\tableofcontents
```
\newpage

分开的

Note: documentclass: report in the metadata will automatically separate the toc from the title, but won't allow to separate it from the remainder of the document.注意:元数据中的documentclass: report会自动将目录与标题分开,但不允许将其与文档的其余部分分开。

Source资源

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

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