且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在 R Markdown 模板中包含图像,而无需为模板创建新目录

更新时间:2023-12-03 21:09:46

我设法通过某种变通方法做到了这一点:

I managed to do this with kind of a workaround:

我使用R函数在yaml头文件中导出资源文件夹的绝对路径:

I derive the absolute path of the resource folder in the yaml header with an R function:

---
output:
  myPackage::myCustomFunction
resource-folder: '`r system.file("rmarkdown/templates/myPackage/resources/", package="myPackage")`'
---

在我使用的 tex 模板中:

Inside my tex tamplate I use:

\includegraphics[]{$resource-folder$myImage.png}

这样我就可以将我的图像与 tex 模板一起放在资源文件夹中,而不必将它们与文档的每个新实例一起复制.

This way I can place my images in the resource folder along with the tex template and don't have to copy them along with each new instance of the document.