Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have researched and found how to create a watermark in an rmarkdown document.

It works great on basic text, but when you have a plot heavy page, it gets hidden behind the plot.

Obviously, this makes it easy for someone to screencap the figures and use them outside of the PDF.

Below is some code that demonstrates the issue clearly.

---
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.


ewpage

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()
```

If anyone is aware of a fix for this, I'd be grateful.

Either making the ggplot backgrounds transparent (which I've tried), or bringing the watermark to the foreground and making it transparent would be ok as far as I'm concerned.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
640 views
Welcome To Ask or Share your Answers For Others

1 Answer

Try using

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

and then on the first page of your document (within the LaTeX part), add

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

This should add a rotated DRAFT message (semi-transparent) in the ForeGround (over top) of the page.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...