I'm creating a RMarkdown document that I want to export in MS Word with RStudio.
I want a table of contents and numbered headings. Here is my sample markdown document:
---
title: "Test"
author: "Ben"
date: "`r format(Sys.time(), '%d/%m/%Y')`"
output:
word_document:
toc: yes
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
# Header 1
## Header 2
## Header 2
### Header 3
This produces the following word doc:
That's a good start. Following this tutorial, I edited the heading styles of the output document in Word to make them numbered.
I also changed the Table of contents title heading so that it's based on normal text and not another heading, otherwise the table of contents title gets numbered as well.
I saved the modified document in a template folder and added it as reference in the markdown header:
---
title: "Test"
author: "Ben"
date: "`r format(Sys.time(), '%d/%m/%Y')`"
output:
word_document:
toc: yes
reference_docx: "../templates/word-styles-reference-01.docx"
---
Here is the output:
Now, I want a page break after my table of contents, so I followed this other tutorial and changed my Heading 6 so that it is white, very small, based on the normal style and adds a page break afterwards.
The new markdown file looks like this:
---
title: "Test"
author: "Ben"
date: "`r format(Sys.time(), '%d/%m/%Y')`"
output:
word_document:
toc: yes
reference_docx: "../templates/word-styles-reference-01.docx"
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
###### Page break after table of contents
# Header 1
## Header 2
## Header 2
### Header 3
And here is the output:
I now have my page break but the Heading 6 title is numbered by Word and thus my first title is numbered 2.
In the end, it's either:
a word question: how do I modify the style of Heading 6 so it's not numbered?
an R question: how can I add a page break without using word headings?
Following on from the Blockquote debate. I found the following solution:
R Markdown
add a block quote with a space
>
Word template
The block quote is formatted as Block Text style in Word.
Edit the Block Text style
small font (I use size 3)
change the paragraph settings
no space before/after
tick "page break before"
There is a few needs for you : first, page break AND unumbered title (see steps 3 & 4), then, maybe you want to adress the size of your titles (see bonus steps) and maybe there is a necessary last stuff to indicate to MS word (see steps 6). In every case, you should manage your word template properly for made a page-break with header 6 and I guess you've miss a step (I translate from the French interface of MS word, maybe there is a few differences in the English version) :
1) First, open your 'reference_docx' in MS word (which is, for you : "../templates/word-styles-reference-01.docx"). It's a good idea to save a copy of that by security.
2) Define a style for header 6 by right-clicking on it in the 'ribon of styles', then select 'modify'.
3) In the dedicated windows for indicate your 'header 6 style' (first case will be 'name : Title 6'), click on 'Format' button ==> then 'numbering' (or 'numbers') ==> then select 'none' ==> Then validate your choice.
4) In the same dedicated windows for modifying styles of 'title 6', click again on 'Format' ==> then on the 'paragraph' button ==> then the second tab named 'chaining' (or 'linking', in french 'enchaînement') ==> click on 'page break before' ==> then validate.
5) Validate your modifications and save your reference word document.
Try at this point to knit your rmardkown to a word output. In your Rmarkdown document, you should made your first notes page with this : ###### [and a space].
Note that if you properly manage your word_template, you gain access to the possibility of a page break with an unumbered title like that : "###### NOTES^[Page left empty.]", wich is better if your page break is a "notes-pages" and not a page-break. If your page-break is only a single 'note-page', you can't define a police-size of 1 for the title.
Bonus step : If you want ONLY a page-break without title, you should define a size of 1 for the police of the title 6. Indicate this in the first screen of 'modifying your title 6' (the one wich begin by 'name : Title 6', after you right-click on your title 6 and then 'modifying'). If you want a note page with a title like 'Notes', you can't define a police size of 1 for your page break.
If the 'title style 6' don't working for made an unumbered page-break, go in the final step (good luck).
5) It's sometimes necessary to go in the list-tools which is in the 'paragraph' ribbon (left to your 'styles ribon') and click on the symbol with a list of '1 / a / i' (the one for define a 'list of several levels') ==> then click on 'define a new list of several levels' ==>
define precisely every title(s) styles with this tools, by clicking on every number of titles at the left (1 to 6 cause you're working in rmarkdown so you had only 6 choices of titles), then click on 'plus' (or 'more') ==> then indicate precisely what you want for this title in the right-part of the 'list of several levels' panel (typically you want to 'restart the list' with every levels, and the page-break 'title 6' maybe need to adress that, you maybe want to center or made indentation for your titles at every steps of the list).
Congratulations, you are free for ms word for a while (except that your titles are in the microsoft blue, and you should write your title in black by playing with every single styles by clicking on 'modifying' for every of them, you should had the same police styles in most of your titles, etc.). Microsoft torture is so elaborate...
As suggested by Frost_Maggot in the comments,
Maybe try modifying a different style in Word that is shared with R
Markdown. If you are not using block quotes in your R markdown this
might relate to quote in the MS Word stylings?
This indeed works for me as I don't use the quote style in my document.
Related
I want to be able to create a PowerPoint output in R (using quarto, qmd) but I've been having some difficulties in the actual format of the powerpoint.
When I execute the following code:
---
title: "My presentation"
subtitle: "January 2023"
author: "Me"
format: pptx
reference-doc: template6.pptx
mainfont: Open Sans
sansfont: Open Sans
---
# Title
## Subtitle
I receive a pptx output with two separate slides, as shown:
What I am looking for is something like in the picture bellow:
A title, in a certain color (and larger size) and bellow a subtitle with another color (with a smaller size).
I've tried messing around with the template, but I didn't find anything close to it.
I know adding it manually would solve the problem, but I'm really adamant about keeping this process as most "automatic" as possible.
Can anyone help?
You can use the slide-level option in your document's YAML header.
So in your case, using:
---
title: "My presentation"
subtitle: "January 2023"
author: "Me"
format: pptx
reference-doc: template6.pptx
mainfont: Open Sans
sansfont: Open Sans
slide-level: 1
---
ensures that new slides are created when a heading is level 1 but not for any subheadings. Alternatively, you can turn off new slide creation via headings by using slide-level: 0 and create new slides manually using horizontal rules (e.g. using three dashes ---).
From the documentation:
slide-level
Specifies that headings with the specified level create slides.
Headings above this level in the hierarchy are used to divide the
slide show into sections; headings below this level create subheads
within a slide. Valid values are 0-6. If a slide level of 0 is
specified, slides will not be split automatically on headings, and
horizontal rules must be used to indicate slide boundaries. If a slide
level is not specified explicitly, the slide level will be set
automatically based on the contents of the document.
When using knitr and rmarkdown together to create a word document you can use an existing document to style the output.
For example in my yaml header:
output:
word_document:
reference_docx: style.docx
fig_caption: TRUE
within this style i have created a default table style - the goal here is to have the kable table output in the correct style.
When I knit the word document and use the style.docx the tables are not stylized according to the table.
Using the style inspector has not been helpful so far, unsure if the default table style is the incorrect style to modify.
Example Code:
```{r kable}
n <- 100
x <- rnorm(n)
y <- 2*x + rnorm(n)
out <- lm(y ~ x)
library(knitr)
kable(summary(out)$coef, digits=2, caption = "Test Captions")
```
I do not have a stylized document I can upload for testing unfortunately.
TL;DR: Want to stylise table output from rmarkdown and knitr automatically (via kable)
Update: So far I have found that changing the 'compact' style in the docx will alter the text contents of the table automatically - but this does not address the overall table styling such as cell colour and alignment.
Update 2: After more research and creation of styles I found that knitr seems to have no problem accessing paragraph styles. However table styles are not under that style category and don't seem to apply in my personal testing.
Update 3: Dabbled with the ReporteRs package - whilst it was able to produce the tables as a desired the syntax required to do so is laborious. Much rather the style be automatically applied.
Update 4: You cannot change TableNormal style, nor does setting a Table Normal style work. The XML approach is not what we are looking for. I have a VBA macro that will do the trick, just want to remove that process if possible.
This is essentially a combination of the answer that recommends TableNormal, this post on rmarkdown.rstudio.com and my own experiments to show how to use a TableNormal style to customize tables like those generated by kable:
RMD:
---
output:
word_document
---
```{r}
knitr::kable(cars)
```
Click "Knit Word" in RStudio. → The document opens in Word, without any custom styles yet.
In that document (not in a new document), add the required styles. This article explains the basics. Key is not to apply direct styles but to modify the styles. See this article on support.office.com on Style basics in Word.
Specifically, to style a table you need to add a table style. My version of Word is non-English, but according to the article linked above table styles are available via "the Design tab, on the Table Tools contextual tab".
Choose TableNormal as style name and define the desired styles. In my experiments most styles worked, however some did not. (Adding a color to the first column and making the first row bold was no problem; highlighting every second row was ignored.) The last screenshot in this answer illustrates this step.
Save the document, e.g. as styles.docx.
Modify the header in the RMD file to use the reference DOCX (see here; don't screw up the indentation – took me 10 minutes find this mistake):
---
output:
word_document:
reference_docx: styles.docx
---
Knit to DOCX again – the style should now be applied.
Following the steps I described above yields this output:
And here a screenshot of the table style dialog used to define TableNormal. Unfortunately it is in German, but maybe someone can provide an English version of it:
As this does not seem to work for most users (anyone but me …), I suggest we test this systematically. Essentially, there are 4 steps that can go wrong:
Wrong RMD (unlikely).
Differences in the initially generated DOCX.
Differences in how the TableNormal style is saved in the DOCX.
Differences in how the reference DOCX is used to format the final DOCX.
I therefore suggest using the same minimal RMD posted above (full code on pastebin) to find out where the results start do differ:
My initially generated DOCX.
The same document with TableNormal added: reference.docx
The final document.
The three files are generated on the following system: Windows 7 / R 3.3.0 / RStudio 0.99.896 / pandoc 1.15.2 / Office 2010.
I get the same results on a system with Windows 7 / R 3.2.4 / RStudio 0.99.484 / pandoc 1.13.1 / Office 2010.
I suppose the most likely culprits are the pandoc and the Office versions. Unfortunately, I cannot test other configurations at the moment. Now it would be interesting to see the following: For users where it does not work, what happens …
… if you start from my initial.docx?
If that does not work, what if you use my reference.docx as reference document?
If nothing works, are there eye-catching differences in the generated XML files (inside the DOCX container)? Please share your files and exact version information.
With a number of users running these tests it should be possible to find out what is causing the problems.
This was actually a known issue. Fortunately, it was solved in v2.0 or later releases of pandoc.
And I have tested the newer version, and found that there is a newly-added hidden style called "Table". Following #CL.'s suggestions to change "Table" style in reference.docx will be okay now.
In addition, look at this entry of pandoc's v2.0 release notes:
Use Table rather than Table Normal for table style (#3275). Table Normal is the default table style and can’t be modified.
As of 2021, I could not get any of the other suggested answers to work.
However, I did discover the {officedown} package, which, amongst other things, supports the styling of tables in .docx documents. You can install {officedown} with remotes::install_github("davidgohel/officedown")
To use {officedown} to render .Rmd to .docx you must replace
output:
word_document
in your document header with
output:
officedown::rdocx_document
In addition to this the {officedown} package must be loaded in your .Rmd.
As with the word_document output format, {officedown} allows us to use styles and settings from template documents, again with the reference_docx parameter.
With a reference document styles.docx, a minimal example .Rmd may look like:
---
date: "2038-01-19"
author: "The Reasonabilists"
title: "The end of time as we know it"
output:
officedown::rdocx_document:
reference_docx: styles.docx
---
```{r setup, include = FALSE}
# Don't forget about me: I'm important!
library("officedown")
```
{officedown} allows us to go one step further and specify the name of the table style to use in the document's front matter. This table style could be a custom style we created in styles.docx, or it could be one of Word's in-built styles you prefer.
Let's say we created a style My Table:
We could tell {officedown} to use this table style in our front matter as:
output:
officedown::rdocx_document:
reference_docx: styles.docx
tables:
style: My Table
Putting this altogether, knitting the minimal .Rmd:
---
date: "2038-01-19"
author: "The Reasonabilists"
title: "The end of time as we know it"
output:
officedown::rdocx_document:
reference_docx: styles.docx
tables:
style: My Table
---
```{r setup, include = FALSE}
# Don't forget about me: I'm important!
library(officedown)
```
```{r}
head(mtcars)
```
Resulting in a .docx document which looks like:
TableNormal doesn't work for me too.
On my Dutch version of Word 2016 (Office 365), I found out that I could markup tables with the style Compact.
Input (refdoc.docx contains the Compact style):
---
title: "Titel"
subtitle: "Ondertitel"
author: "`r Sys.getenv('USERNAME')`"
output:
word_document:
toc: true
toc_depth: 2
fig_width: 6.5
fig_height: 3.5
fig_caption: true
reference_docx: "refdoc.docx"
---
And RMarkdown:
# Methoden {#methoden}
```{r}
kable(cars)
```
Output:
You need to have a reference_docx: style.docx which has "Table" style in it. (see #Liang Zhang's explanation and links above).
Create a basis reference document using pandoc (source). In command line (or cmd.exe on Windows) run:
pandoc -o custom-reference.docx --print-default-data-file reference.docx
In this newly created reference.docx file, find the table created (a basic 1 row table with a caption).
While the table is selected, click "Table Design" and find "Modify Table Style":
Modify the style of the table as you wish and use this reference document in your RMD document (see the first answer by #CL.).
Using this reference document, you can also change the table and figure caption styles.
I was able to get my word output to use a default table style that I defined in a reference .docx.
Instead of 'TableNormal', the table style it defaulted to was 'Table'.
I discovered this by knitting an rmarkdown with a kable.
---
date: "December 1, 2017"
output:
word_document:
reference_docx: Template.docx
---
`r knitr::kable(source)`
Then I took a look at that generated document's XML to see what style it had defaulted to.
require(XML)
docx.file <- "generated_doc.docx"
## unzip the docx converted by Pandoc
system(paste("unzip", docx.file, "-d temp_dir"))
document.xml <- "temp_dir/word/document.xml"
doc <- xmlParse(document.xml)
tblStyle <- getNodeSet(xmlRoot(doc), "//w:tblStyle")
tblStyle
I defined the 'Table' style to put some color and borders in the reference docx. This works for one standard table style throughout the document, I haven't found a way to use different styles throughout.
This stayed true even after I opened the reference doc and edited it.
I am creating a presentation with Rstudio using knitr and I want to use the types of the slides to generate a table of contents slide in the beginning. So if I have the following code:
Some fun lecture
========================================================
author: some guy
date: in the future
Table of content slide
========================================================
Here I want the table of content based on the following slide types
Some stuff 1
========================================================
type:section
Some very important stuff
More detail on stuff 1
========================================================
type:subsection
Did not get enough of stuff 1!? Here is more :D
Stuff 2
========================================================
type:section
There are other kinds of stuff?
Prompt slide
========================================================
type:prompt
Do not display prompt or alert types in TOC
So basically I want a table of content slide after the title slide looking something like:
Some stuff 1
More detail on stuff 1
Stuff 2
Is this available by default or do I need some extra CSS style in the beginning to handle this?
To generate a table of contents, include a document header with the option "toc:true" at the beginning of the document. Level 1 headings are indicated by #, level 2 headings by ##, and so on. Below is an example . The "prompt" option is only relevant for R code chunks. R code chunks are not listed in the table of contents.
This will, however, only produce a html document. If you want a Latex-like presentation with individual slides, you can replace html_document with beamer_presentation. In the beamer presentation, only level 1 headings are listed in the table of contents.
---
title: "Sample Document"
author: "Author"
output:
html_document:
toc: true
---
# Some stuff 1
Some very important stuff
## More detail on stuff 1
Did not get enough of stuff 1!? Here is more :D
# Stuff 2
There are other kinds of stuff?
```{r, prompt=TRUE}
summary(iris[, "Sepal.Length"])
```
For more info on Beamer presentations in Rmarkdown, see http://rmarkdown.rstudio.com/beamer_presentation_format.html. A similar question has been answered here.
This is my first questions on StackOverflow, so please let me know if I'm doing anything wrong.
I'm using R to generate a lot of very large PDF documents. My data is about 580,000 observations, and breaks down in to 32 categories with each category containing 70 answers to between 20 and 300 questions. Currently I use two for loops (I try to avoid for loops, but for creating these pdfs it was the only way that worked). The first goes through and creates a pdf for the category with a title page, then the second adds a page for each graph showing the results of that question. I'm using ggplot2 & the "pdf" function.
The script works great, creating 32 pdfs (one for each category) with a custom title page and pages for all the questions in that category. I would like to add a Table of Contents after the title page. I know how to add a page with labels and page numbers, but I need one that links to each question.
I've searched this site and Google, but haven't found any way to do this in R. This question: Adding a table of contents to PDF with R plots talks about using RPython. I've also come across sources mentioning "hyperref", LaTex, Pandoc, and Knitr. I know how to use Kintr in an Rmarkdown doc, but that doesn't work for what I'm trying to do. I'm not really sure how to work with any of the others, so solutions with using them went over my head.
Is there not a way to work with creating a Table of Contents or just hyperlinks to PDF pages inside R, without going to those other languages?
Have you tried just clicking on the section names in the table of contents? By default, these seem to be hyperlinked, although there isn't any colouration that hints at it.
To help you see what might be happening, add / change your YAML header to add the following:
output:
pdf_document:
keep_tex: true
toc: true
toc_depth: 3
That will get the intermediate .tex file kept. If you open that up after knitting, you should already see references to hyperref in it.
I then find my table of contents being defined as:
{
\hypersetup{linkcolor=black}
\setcounter{tocdepth}{3}
\tableofcontents
}
which produces a hyperlinked TOC, but with "black" hyperlinks!
If you want to change the colour and see them show up, you can open the tex file in RSudio and simply change the "black" to "blue" and have RStudio run "Compile PDF" and you should see them showing up.
If you want your page numbers hyperlinked rather than the description, add the following into your YAML:
header-includes:
- \hypersetup{linktocpage}
Share & Enjoy!
I just remembered I left this open and thought I'd go back and post how I ended up solving it, well sorta. Instead of an R script, I used a R Markdownfile to create a combined pdf, which included all sections with their subsequent questions as different levels. I was able to create a pdf for each section individually with a linked clickable Table of Contents including all of its questions(pages) and different header levels for title pages.
The key was pandoc.header, which allowed me to create the headers, which show in the TOC. I think neither the for loops, nor the ggplot, which was created for each page, is relevant. Here is an overview of the .rmd :
title:
author:
output:
pdf_document:
toc: true
```{r results = "asis", message=FALSE, warning=FALSE, echo=FALSE, fig.height = 11, fig.width = 8}
for(i in 1:length(categories){
pandoc.header(paste("Category ",category_num, ": ", category discription), level = 1)
category title page
for(i in 1:numberofquestions){
pandoc.header(paste("Question ",question_num, ": ", subtitle1), level = 2)
print(ggplot())
}}
```
The only inconvenient part is that each page must have a header to be linked to and I really didn't like the title pages having one, but it looks like I can manually edit that out with what dsz posted.
I writing a Word document with R markdown in R Studio. I can get many things, but at the moment I am not figuring out how can I get a page break. I have found solutions but only for rendered latex / pdf document that it is not my case.
Added: To insert a page break, please use \newpage for formats including LaTeX, HTML, Word, and ODT.
https://bookdown.org/yihui/rmarkdown-cookbook/pagebreaks.html
Paragraph before page break.
\newpage
First paragraph on a new page.
Previously: There is a way by using a fifth-level header block (#####) and a docx template defined in YAML.
After creating headingfive.docx in Microsoft Word, you select Modify Style of the Heading 5, and then select Page break before in the Line and Page Breaks tab and save the headingfive.docx file.
---
title: 'Making page break using fifth-level header block'
output:
word_document:
reference_docx: headingfive.docx
---
In your Rmd document, you define reference_docx in the YAML header, and now you can use the page-breaking #####.
Please see below.
https://www.r-bloggers.com/r-markdown-how-to-insert-page-breaks-in-a-ms-word-document/
With the help of John MacFarlane and others on the pandoc google group, I put together a filter that does this. Please see:
https://groups.google.com/forum/#!topic/pandoc-discuss/FzLrhk0vVbU
In short, the filter needs to look for something to replace with the openxml for pagebreak. In this case
\newpage
is being replaced with
<w:p><w:r><w:br w:type=\"page\"/></w:r></w:p>
This allows for a single latex markup to be interpreted for both pdf and word output.
Joel
What you are trying to do is force a "page break" or "new page" in a word document generated with Pandoc. I have found a way to do this in my environment but I'm not sure it will work in every environment.
My environment:
* R-studio / Pandoc / MS-WORD starting with an "*.Rmd" file and generating a DOCX file.
In my RMD file the key idea is that i've created what acts like a TEMPLATE document (MyFormattingDocument.docx) and in that word document I tweak the STYLES for things like "Heading 1" and/or "Heading 2" and or "footnote" or whatever other predefined styles I want to tweak.
(SEE THIS: http://rmarkdown.rstudio.com/word_document_format.html#style-reference ) for explanation of style reference and how to set the header information in your RMD file to specify a reference document.
SOOOO in my case... i tweak the "Heading 1" style in WORD to include a forced "Page Break Before" in the Paragraph formatting for "Heading 1". Exactly how you force every "Heading 1" to always "Page Break" is different in different versions of Microsoft WORD but if you follow the WORD documentation and modify the "Heading 1" style THEN every "Heading 1" will always have a pagebreak before it.
THEN... you save this template file in the some directory you're working from with the RMD file... and it is USED AS a template. THE CONTENTS of the file are ignored.... so don't worry... you can put sample text in this file and test that the formatting all works.... THE CONTENTS ARE IGNORED but the STYLES are USED in the new word document which will be built by the RMD file so.... then every "Heading 1" will have a break before it.
NOTE: You could obviously do the same with ANY style that has a one-to-one mapping from PANDOC MARKUP so you could instead just make all "Heading 3" or whatever.... just look at see in your RMD created DOCX what "STYLE" is being applied and then tweak that style even if you need to insert some "fake" lines with essentially blank content just for the purpose of forcing a style to appear in the DOCX
Here is an R script that can be used as a pandoc filter to replace LaTeX breaks (\pagebreak) with word breaks, per #JAllen's answer above. With this you don't need to compile a pandoc script. Since you are working in R Markdown I assume one has R available in the system.
#!/usr/bin/env Rscript
json_in <- file('stdin', 'r')
lat_newp <- '{"t":"RawBlock","c":["latex","\\\\newpage"]}'
doc_newp <- '{"t":"RawBlock","c":["openxml","<w:p><w:r><w:br w:type=\\"page\\"/></w:r></w:p>"]}'
ast <- paste(readLines(json_in, warn=FALSE), collapse="\n")
ast <- gsub(lat_newp, doc_newp, ast, fixed=TRUE)
write(ast, "")
Save this as page-break-filter.R or something like that and make it executable by running chmod +x page-break-filter.R in the terminal.
Then include this filter the R Markdown YAML like so:
---
title: "Title
author: "Author"
output:
word_document:
pandoc_args: [
"--filter", "/path/to/page-break-filter.R"
]
---
You can use the R package worded. This avoids the need for a template word file. See https://github.com/davidgohel/worded.
The output parameter needs to be set to worded::rdocx_document and you need to call library(worded).
---
date: "2018-03-27"
author: "David Gohel"
title: "Document title"
output:
worded::rdocx_document
---
```{r setup, include=FALSE}
library(worded)
```
You can then add <!---CHUNK_PAGEBREAK---> to your document whenever you want a page break.
The package allows various word formatting options using a similar mechanism.
When updating to R 4.0.0, the <!---CHUNK_PAGEBREAK---> solution was not working any more for me.
Instead I could use the run_pagebreak() function from the officer package, still in combination with the officedown package:
---
output: word_document
---
```{r settings}
library(officedown)
library(officer)
```
Hello world on page 1
`r run_pagebreak()`
Hello world on page 2
R Markdown 1.16 introduced a new feature which allows to insert a page break by adding a paragraph that contains only the commands \pagebreak or \newpage:
Paragraph before page break.
\pagebreak
First paragraph on a new page.
See also the pagebreaks section in the R Markdown cookbook.
It is not an automated solution. But I have been adding the text '#####page break' to my markdown document. Then in MS Word using find-replace to replace the text "page break" with "^m" (manual page break).
Sungpil's article was close, but didn't quite work. This was the best solution I found for this:
https://scriptsandstatistics.wordpress.com/2015/12/18/rmarkdown-how-to-inserts-page-breaks-in-a-ms-word-document/
Even better, the author included the Word template to make this work. The R-blogger's link to his template is broken, and the header is formatted wrong. Some notes I took:
1) You might need to include the whole path to the word template in your Rmd header, like so:
output:
word_document:
reference_docx: C:/workspace/myproject/mystyles.docx
2) The template at the link above changed some of the default style settings so you'll need to change them back
My solution is not very robust but can work for some of us.
Assuming you need a page break before each level 1 title in your word document, I defined this in the format template used in the yaml field reference_docx: .
In this document you modify the Heading 1 format (or equivalent) to insert a page break before the Title. Do not forget to start your template with the first docx rendered with knitr (pandoc) in RStudio.
Ok, I found this in the markdown docs.
Horizontal Rule / Page Break
Three or more asterisks *** or dashes ---.