1

I'm trying to get a watermark image like here:

How to add a watermark image on rmarkdown?

I almost did it, but as I wrote on my original question the background.png image that the \includegraphics get comes from C:\Program Files (x86)\MiKTeX 2.9\tex\plain\present

I'm currently using my Latex code from an external file using the follwing at beginning of my .Rmd:

output:
  pdf_document:
    includes:
      in_header: header.tex

And in header.tex I'm using the following code:

\usepackage{eso-pic,graphicx,transparent}
\AddToShipoutPictureFG{
\put(0,0){%
\parbox[b][\paperheight]{\paperwidth}{%
\centering
  {\transparent{0.3} \includegraphics[width=\paperwidth,height=\paperheight,%
keepaspectratio]{background.png}}%
    }
  }
}

But I just can't get the background.png from where my .tex file is (that is the same that my .Rmd file is).

How I tell to my .tex file get this image from the relative path to my .tex?

--EDIT-- I'm using the render function from rmarkdown to make the report, follow is a screenshot from the insides of my folder with .Rmd, the .tex file and the error when I try to insert a test.png:

rstudio screenshot

Community
  • 1
  • 1
  • 1
    What is the actual error? I have used `\includegraphics{...}` lots of times via `rmarkdown`, mostly with a simple subdirectory as in, say, `\includegraphics{figures/someChart.pdf}`. Pandoc just passes that through unchanged and (la)tex processes as usual. – Dirk Eddelbuettel Oct 03 '16 at 14:19
  • If I change the background.png to test.png, for instance, it gives me the error: `! Package pdftex.def Error: File 'test.png' not found. See the pdftex.def package documentation for explanation. Type H for immediate help.` – Luiz Fernando Moratelli Oct 03 '16 at 16:03

2 Answers2

1

"It works for me." Here is a minimal Rmarkdown file, trimmed down from one of the templates offered by RStudio:

---
title: "Demo"
author: "Dirk"
date: "October 3, 2016"
output: pdf_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## R Markdown

This is an R Markdown document. We include one figure

\includegraphics{Rlogo.png}

La fin.

I can hit the knit button just fine, or run this by hand:

/tmp$ cat includeDemo.Rmd
---
title: "Demo"
author: "Dirk"
date: "October 3, 2016"
output: pdf_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## R Markdown

This is an R Markdown document. We include one figure

\includegraphics{Rlogo.png}

La fin.

/tmp$ Rscript -e 'rmarkdown::render("includeDemo.Rmd")'


processing file: includeDemo.Rmd
  |......................                                           |  33%
  ordinary text without R code

  |...........................................                      |  67%
label: setup (with options) 
List of 1
 $ include: logi FALSE

  |.................................................................| 100%
  ordinary text without R code


output file: includeDemo.knit.md

/usr/bin/pandoc +RTS -K512m -RTS includeDemo.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output includeDemo.pdf --template /usr/local/lib/R/site-library/rmarkdown/rmd/latex/default-1.15.2.tex --highlight-style tango --latex-engine pdflatex --variable graphics=yes --variable 'geometry:margin=1in' 

Output created: includeDemo.pdf
/tmp$ 

Maybe something is playing tricks with you by switching from the current directory to a temporary processing directory. In which an (icky!!) absolute path may help...

enter image description here

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
1

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.

Community
  • 1
  • 1