15

I'm using Rstudio to make a markdown document which I want to convert to a word document. I would like to change word template that is automatically generated when you knit to Word. For example, I want the margins to be narrow when I knit to word.

I'm on a Windows 64 bit, with Windows 7.

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
LeslieKish
  • 414
  • 1
  • 4
  • 11

2 Answers2

19

I prepared a video for this task. Please see if it helps. Basically you generate a Word document from an arbitrary R Markdown document, then modify the styles in the Word output document, and use this document as the template for future R Markdown documents.

Yihui Xie
  • 28,913
  • 23
  • 193
  • 419
  • How do you target the italic and bold formats? I see Emphasis and Strong in the styles list, but any bold or italicized font is styled with BodyText and then modified with the additional style. I want to modify the inline source code format for non-R code and this was the best approach I could think of since changing the SourceCode style affects code chunks as well. Are there resources out there that show how to do this? Thanks! – tblznbits Feb 10 '17 at 14:24
  • 5
    If you create a Word template that includes a header and/or footer, is there a way to dynamically specify the header/footer text when knitting or rendering? For example, is there a way to change the header text in the YAML or within the `word_document` command? Or does the header/footer text have to be "hard-coded" into the Word template document? – eipi10 Sep 03 '17 at 20:35
  • @brittenb can you elaborate? Could you not simply add `**HERE IS BOLD TEXT** ` within your RMarkdown document? – Patrick Feb 22 '19 at 13:56
3

To use a specific template or styled document, you can create a file with the appropriate styling and reference this file in the YAML header of your markdown file. As described in this article: https://rmarkdown.rstudio.com/articles_docx.html

---
output:
  word_document: 
    reference_docx: "filepath\\ref.docx"
---
MatAff
  • 1,250
  • 14
  • 26