17

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.

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

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.

Calum
  • 1,889
  • 2
  • 18
  • 36
John Tarr
  • 717
  • 1
  • 9
  • 21
  • See cowplot package. – zx8754 Sep 23 '15 at 19:50
  • If you need things stamped as your own, you could add copyright text to the offending plots themselves, which would protect you from the screen cap. – Shawn Mehan Sep 23 '15 at 19:50
  • [cowplot](https://cran.r-project.org/web/packages/cowplot/index.html) – Shawn Mehan Sep 23 '15 at 19:51
  • 1
    I see the annotations in cowplot, but really want to avoid having each chart with an annotation. I suppose I could assign it to a variable, but I'd really like to have one place in the document where I turn on / off the watermark. – John Tarr Sep 23 '15 at 19:59

1 Answers1

13

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]{\rotatebox[origin=c]{45}{%
      \scalebox{5}{\texttransparent{0.3}{DRAFT}}%
    }}
  }
}

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

Werner
  • 14,324
  • 7
  • 55
  • 77
  • This is awesome. Thank you! Only one question. I simplified for this example, but typically, I use `in_header: header.tex` to store my tex includes and functions. I currently just have a `\blandscape` and `\elandscape` to start and stop landscape. I tried adding your code to my `header.tex` as a new function called `\markasdraft`, and it works, but it only worked for a single page. Any idea how to make this work as a function that I could call with one line? Pasting my header.tex in the next comment. – John Tarr Sep 24 '15 at 13:54
  • \usepackage{lscape} \usepackage{eso-pic,graphicx,transparent} \newcommand{\blandscape}{ \begin{landscape} \pagebreak[4]\global\pdfpageattr\expandafter{\the\pdfpageattr/Rotate 90}} \newcommand{\elandscape}{ \end{landscape} \pagebreak[4]\global\pdfpageattr\expandafter{\the\pdfpageattr/Rotate 0}} \newcommand{\markasdraft}{ AddToShipoutPictureFG{ \AtPageCenter{% or \AtTextCenter \makebox[0pt]{\rotatebox[origin=c]{45}{% \scalebox{5}{\texttransparent{0.3}{DRAFT}}% }} } } } – John Tarr Sep 24 '15 at 13:54
  • @JohnTarr: You seem to be missing a ``\``. With a call to `\markasdraft`, it should activate the DRAFT *from that point forward*. Otherwise, if you only want it for a single page, then one would use `\AddToShipoutPictureFG*` (the starred version). – Werner Sep 24 '15 at 14:44
  • Confirmed. It was the missing backslash. Thanks again. Now I can make one line calls for `\markconfidential`, etc as well. – John Tarr Sep 24 '15 at 18:40