Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Watermark in rmarkdown

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.

like image 208
John Tarr Avatar asked Sep 23 '15 19:09

John Tarr


People also ask

How do I add blank space in R Markdown?

Blank Lines To add a single extra line after a paragraph, add two extra spaces at the end of the text. To add an extra line of space between paragraphs, add the HTML   code, followed by two extra spaces (e.g. &nbsp.. , replacing the periods with spaces).

Can you add image to R Markdown?

To insert an image, you can also use an R code chunk. --- title: "R Markdown Tips and Tricks" output: html_document --- You can also insert an image using R code: ```{r} knitr::include_graphics("img/rmarkdown_hex. png") ``` The image looks smaller by default though.

How do you insert a line break in R Markdown PDF?

Add Line Breaks in R Markdown To break a line in R Markdown and have it appear in your output, use two trailing spaces and then hit return .

What is knitr R Markdown?

RMarkdown is an extension to markdown which includes the ability to embed code chunks and several other extensions useful for writing technical reports. The rmarkdown package extends the knitr package to, in one step, allow conversion between an RMarkdown file (.Rmd) into PDF, HTML, word document, amongst others.


1 Answers

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.

like image 100
Werner Avatar answered Sep 21 '22 12:09

Werner