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?
quote
in the MS Word stylings? – Frost_Maggotquote
(which I don't for now) – Ben