将背景图像添加到R Markdown(.rmd)文件以进行PDF输出?

Joh*_*nny 2 pandoc r-markdown

是否可以将背景图像添加到R Markdown(.rmd)文件以进行PDF输出?

我已经通过Pandoc的R Markdown文档进行了搜索,但是没有找到添加背景图像的提及.

sco*_*coa 6

这个tex.SE答案:保存以下内容header.tex(将image.jpg替换为背景图像的路径):

\usepackage{background}

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

并添加到您的yaml:

---
output: 
  pdf_document:
    includes:
      in_header: header.tex
---
Run Code Online (Sandbox Code Playgroud)

有关如何自定义输出的提示,请参阅background文档.

  • 你好,超级有用。我也实现了它,但左右仍有一些小边距,因此背景不会在文档的整个宽度上缩放。我检查了几何包,但将边距设置为 0 时没有对图像应用任何更改。您在这里有提示吗?谢谢! (2认同)