Adding background image to R Markdown (.rmd) file

2019-03-22 04:57发布

问题:

Is it possible to add a background image to a R Markdown (.rmd) file for PDF output?

I have scoured through Pandoc's R Markdown documentation but cannot find any mention of adding a background image.

回答1:

From this tex.SE answer: save the following as header.tex (replacing image.jpg by the path to your background image):

\usepackage{background}

\backgroundsetup{
scale=1,
color=black,
opacity=0.4,
angle=0,
pages=all,
contents={%
  \includegraphics[width=\paperwidth,height=\paperheight]{image.jpg}
  }%
}

And add to your yaml:

---
output: 
  pdf_document:
    includes:
      in_header: header.tex
---

See the background documentation for tips on how to customize the output.