rmarkdown中的水印

时间:2015-09-23 19:46:29

标签: r latex knitr r-markdown watermark

我研究并发现了如何在rmarkdown文档中创建水印。

它在基本文本上效果很好,但是当你有一个情节重页时,它会隐藏在情节背后。

显然,这使得某人可以轻松地屏蔽数字并在PDF之外使用它们。

以下是一些能够清楚地说明问题的代码。

---
title: "Testing Watermark"
author: "John"
date: "September 18, 2015"
header-includes:
   - \usepackage{draftwatermark}
output:
  pdf_document
---

This is some basic text.  
Note the watermark on this page, and the hidden watermark on the next page.

\newpage

\SetWatermarkText{DRAFT}

```{r echo=FALSE, warning=FALSE, message=FALSE, fig.height=7}
library(ggplot2)

ggplot(mtcars) +
  geom_point(aes(mtcars$mpg, mtcars$cyl)) +
  facet_wrap(~carb, ncol=1) + 
  theme_bw()
```

如果有人知道对此有所修正,我将不胜感激。

要么让ggplot背景透明(我已经尝试过),或者将水印带到前台并使其透明,就我而言是可以的。

1 个答案:

答案 0 :(得分:6)

尝试使用

header-includes:
   - \usepackage{eso-pic,graphicx,transparent}

然后在文档的第一页(在LaTeX部分中),添加

\AddToShipoutPictureFG{
  \AtPageCenter{% or \AtTextCenter
    \makebox[0pt]{\rotatebox[origin=c]{45}{%
      \scalebox{5}{\texttransparent{0.3}{DRAFT}}%
    }}
  }
}

这应该在页面的F矿石G轮次(顶部)添加一个轮换的DRAFT消息(半透明)。