如何从 Rmarkdown 中的 .tex 文件夹(相对路径)获取图像?
How to get images from the .tex folder (relative path) in Rmarkdown?
我正在尝试像这里一样获取水印图像:
How to add a watermark image on rmarkdown?
我几乎做到了,但正如我在最初的问题中所写的那样,\includegraphics
获得的 background.png
图片来自 C:\Program Files (x86)\MiKTeX 2.9\tex\plain\present
我目前正在使用 .Rmd 开头的以下外部文件中的 Latex 代码:
output:
pdf_document:
includes:
in_header: header.tex
在 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
的相对路径获取此图像?
--编辑--
我正在使用 rmarkdown
中的 render
函数来制作报告,下面是我的文件夹内部的屏幕截图,其中包含 .Rmd、.tex 文件以及我尝试插入 test.png
:
"It works for me." 这是一个最小的 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$
可能有什么在耍你,从当前目录切换到临时处理目录。其中(恶心!!)绝对路径可能会有所帮助...
我刚刚做到了。
问题出在 Windows 的 MiKTeX 上。
我只是按照 this answer 上的步骤操作,记得确保该文件夹符合 TDS(其中有一个 tex
文件夹),然后我将图像放在 tex
文件夹。
我正在尝试像这里一样获取水印图像:
How to add a watermark image on rmarkdown?
我几乎做到了,但正如我在最初的问题中所写的那样,\includegraphics
获得的 background.png
图片来自 C:\Program Files (x86)\MiKTeX 2.9\tex\plain\present
我目前正在使用 .Rmd 开头的以下外部文件中的 Latex 代码:
output:
pdf_document:
includes:
in_header: header.tex
在 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
的相对路径获取此图像?
--编辑--
我正在使用 rmarkdown
中的 render
函数来制作报告,下面是我的文件夹内部的屏幕截图,其中包含 .Rmd、.tex 文件以及我尝试插入 test.png
:
"It works for me." 这是一个最小的 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$
可能有什么在耍你,从当前目录切换到临时处理目录。其中(恶心!!)绝对路径可能会有所帮助...
我刚刚做到了。
问题出在 Windows 的 MiKTeX 上。
我只是按照 this answer 上的步骤操作,记得确保该文件夹符合 TDS(其中有一个 tex
文件夹),然后我将图像放在 tex
文件夹。