Rmarkdown to Word output - insert image above header

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-22 11:04:20

问题


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.



来源:https://stackoverflow.com/questions/31021880/rmarkdown-to-word-output-insert-image-above-header

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!