Watermark in Rmarkdown

Watermark in rmarkdown

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.

Add a 'DRAFT' watermark on pdf result of R markdown

Try this

---
title: "Untitled"
header-includes:
- \usepackage{draftwatermark}
output:
pdf_document:
keep_tex: yes
---

```{r, results='asis'}
cat(sample(c("\n",letters), 1e4, TRUE))
```

Insert a logo in upper right corner of R markdown pdf document

Ok, I have found the solution:

---
title:
header-includes:
\usepackage{graphicx}
\usepackage{fancyhdr}
\pagestyle{fancy}
\setlength\headheight{28pt}
\fancyhead[L]{\includegraphics[width=5cm]{GPIM_Logo_300x85.png}}
\fancyfoot[LE,RO]{GPIM}
output: pdf_document
---

Watermark adding in R

For instance, this

download.file("https://i.stack.imgur.com/7X5To.png", tf<-tempfile(fileext = ".png"), mode="wb")
library(magick)
img <- image_read(tf)
library(extrafont)
truetype_path <- paste0("@", subset(fonttable(), FullName=="Matura MT Script Capitals", fontfile)[1,])
image_annotate(img, "my watermark", gravity = "northwest", location = "+70+220",
degrees = -30, size = 80, font = truetype_path, color = "#FFFFFF66",
strokecolor = NULL, boxcolor = NULL)

gives this image:

Sample Image

I.e., choose a nice font like maybe Matura MT Script Capitals, tell image_annotate where to find it on your harddrive, adjust the opacity in the color argument - et voila. The font does not drop a shadow or show a relief, but maybe you can emulate this by plotting the text two times, the dark shadow one with a little offset to the other light one.

Adding text string to existing pdf doc

If (free command line) version of pdftk is an acceptable auxiliary tool, then you can automate the solution from this question in R (i.e., using the stamp operation in pdftk):

Generate PDF to experiment with:

pdf("test1.pdf")
plot(1:10,1:10)
dev.off()

Generate "watermark" overlay:

pdf("stamp.pdf")
par(fg="white")
## to match spacing etc - 'phantom' plot
plot(1:10,1:10, type="n", axes=FALSE, ann=FALSE)
par(fg="black")
text(5,5, "watermark", col=adjustcolor("gray", alpha.f=0.2), cex=5)
dev.off()

Call pdftk to do the overlay:

system("pdftk test1.pdf stamp stamp.pdf output test1S.pdf")

Results:

plot with added watermark

I think the fussy part will be getting the spacing in the overlay file the way you want it ... although you could use grid graphics, or create a zero-margin/zero-annotation plot so that the plotting area had bounds (0,1) x (0,1) ...

How to get images from the .tex folder (relative path) in Rmarkdown?

I just did it.

The problem were on MiKTeX for Windows.

I just followed the steps on this answer, remembering to assure that the folder is TDS-compliant (with a tex folder in it), and after I just put the image on the tex folder.

add image in title page of rmarkdown pdf

I was able to solve this using LaTeX package titling

---
title: "Untitled"
author: "Name"
date: "September 19, 2015"
output:
pdf_document:
includes:
in_header: header.tex
---

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.

When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

```{r}
summary(cars)
```

You can also embed plots, for example:

```{r, echo=FALSE}
plot(cars)
```

Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.

Where the header.tex should include the following code:

\usepackage{titling}

\pretitle{%
\begin{center}
\LARGE
\includegraphics[width=4cm,height=6cm]{logo.png}\\[\bigskipamount]
}
\posttitle{\end{center}}

and replace logo.png with the image you would like to use and make sure the file is in the root directory of your Rmd file. You can change image width and height to your needs. For more information on available options go to titling



Related Topics



Leave a reply



Submit