Rmarkdown to Word output - insert image above head

2019-05-10 02:31发布

问题:

I have an Rmarkdown document which I'm outputting to Word and I'm trying to insert a company logo to the top of the page, above the header that includes the title and author.

I haven't found a solution to this. I've tried using pandoc_args to --include-in-header, but this wasn't successful. I'm not confident that I was using it correctly though.

Is it possible to include an image above the header?

---
title: "Untitled"

author: "r.bot"
date: "Thursday, January 1, 2015"
output:
  word_document:
    fig_caption: yes
    fig_height: 5
    fig_width: 5
    reference_docx: template.docx
    pandoc_args:  [
      "--include-in-header", "C:\\path\\to\\file.png"
    ]
---

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.

回答1:

This is possible using image headers in a Word template. In Word 2010 go: insert header -> image and add the image of choice. Save this document as template_image.docx in the same folder as the .Rmd file.

Then, in the YAML header:

---
title: "Untitled"
author: "Simon"
date: "Thursday, May 21, 2015"
output:
  word_document:
    fig_caption: yes
    fig_height: 5
    fig_width: 5
    reference_docx: template_image.docx
---

Knit the .Rmd file and the output should include the image.



标签: r r-markdown