2016-10-03 66 views
0

我試圖得到一個水印圖像喜歡這裏:如何從Rmarkdown中的.tex文件夾(相對路徑)獲取圖像?

How to add a watermark image on rmarkdown?

我幾乎做到了,但正如我在我原來的問題寫了background.png圖像的\includegraphics獲取來自C:\Program Files (x86)\MiKTeX 2.9\tex\plain\present

output: 
    pdf_document: 
    includes: 
     in_header: header.tex 

和:我使用的是follwing我.Rmd的開始目前使用我的乳膠代碼從外部文件在header.tex我使用下面的代碼:

\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}}% 
    } 
    } 
} 

但我只是不能從那裏我.tex文件是background.png(即相同的,我的.Rmd文件)。

我如何告訴我的.tex文件從相對路徑中獲取此圖像到我的.tex

- 編輯 - 我使用的render功能從使報告,遵循的是我與.Rmd,在.tex文件和文件夾錯誤的內部截圖,當我嘗試插入一個test.png

rstudio screenshot

+1

什麼是實際錯誤?我通過'rmarkdown'多次使用了'\ includegraphics {...}',其中大部分都使用了簡單的子目錄,例如'\ includegraphics {figures/someChart.pdf}'。 Pandoc只是通過不變的和(la)tex的過程像往常一樣。 –

+0

如果我將background.png更改爲test.png,例如,它給了我錯誤:'!包pdftex.def錯誤:找不到文件'test.png'。 有關說明,請參閱pdftex.def包文檔。 H型即時幫助.' –

回答

0

我只是做了它。

問題出在Windows的MiKTeX上。

我只是遵循的步驟上this answer,記住要確保該文件夾是TDS-標準(與它tex文件夾),之後我只是把圖像上的tex文件夾。

1

「這對我的作品。」下面是一個最小的Rmarkdown文件,從由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. 

我可以打knit按鈕就好了,或者手工運行這個命令:

/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$ 

也許東西通過從當前目錄切換到臨時處理目錄與您玩技巧。在其中(噁心!!)絕對路徑可以幫助...

enter image description here