-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path03-templates.Rmd
77 lines (58 loc) · 3.03 KB
/
03-templates.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# Templates {#template}
1. Built-in templates
1. Templates from R packages
1. User-defined templates
## Built-in templates {#builtin}
R Markdown has several built-in output templates that you just have to specify them with the YAML `output` option.
These include:
- Documents
- `html_document`
- `pdf_document`
- `word_document`
- [Presentations](https://rmarkdown.rstudio.com/lesson-11.html)
- `ioslides_presentation` and `slidy_presentation` for HTML
- `beamer_presentation` for PDF
- `powerpoint_presentation`
- Interactive [Shiny](https://bookdown.org/yihui/rmarkdown/shiny-documents.html) documents and presentations
## Templates from R packages {#packages}
You can also download specific templates from CRAN or GitHub.
You use them the same way as the built-in templates by specifying them in the YAML header.
A few that I've used or played with include:
- Presentations: [`revealjs`](https://cran.r-project.org/web/packages/revealjs/index.html)
- CVs: [`vitae`](https://github.com/mitchelloharawild/vitae)
- Academic posters: [`posterdown`](https://github.com/brentthorne/posterdown)
- APA-formatted articles: [`papaja`](https://github.com/crsh/papaja)
- Journal templates: [`rticles`](https://bookdown.org/yihui/rmarkdown/rticles-templates.html)
- HTML theme: [`prettydoc`](https://github.com/yixuan/prettydoc)
- Manuscripts: [single document](https://bookdown.org/yihui/rmarkdown/bookdown-output.html#a-single-document) output from [`bookdown`](https://bookdown.org/yihui/bookdown/)
## User-defined templates {#usedef}
There are also ways to include templates for other output types in the YAML header.
### PDF
For PDFs, you can include LaTeX templates, but you need to pay attention to the use of \$.
The PLOS template referenced in the example below failed to compile when I first downloaded it, because \$ are special characters for pandoc.
After I added a second \$ throughout the document (just using *find and replace*), it worked.
```
---
output:
pdf_document:
template: plos_latex_template.tex
---
```
See Section \@ref(latexpacks) for calling specific LaTeX packages in R Markdown.
### Word
You can also set up Word templates.
To do this, you need to use the *Styles Pane* in the Word Document you want to use as a template.
Highlight the text you want to format, make the desired changes, then find the style that applies to that section, and find *Update to Match Selection* in the dropdown menu.
In the example below, you can see that I'm editing the *Header 1* format, so I need to update that particular entry in the *Styles Pane*.
I like to check the *Show styles guide* option at the bottom of the *Styles Pane*, which filters the list of styles to just the ones used in the document and marks them in the document.
```{r template_word, echo=FALSE}
knitr::include_graphics("images/template_word.png")
```
You have to go through this editing process for every text element in the document, but once you've set it up, you can simply include it in the YAML header.
```
---
output:
word_document:
reference_docx: template.docx
---
```