在 R Markdown 模板中包含图像,而无需为模板创建新目录 [英] Include Image in R Markdown Template Without Having to Create a New Directory for Template

查看:43
本文介绍了在 R Markdown 模板中包含图像,而无需为模板创建新目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个投影仪演示模板,我想在幻灯片的正面包含一个徽标.虽然这可以通过在演示文稿的目录中包含一个图像来实现,但我不想为每个新演示文稿只为那张图像创建一个新目录.

I’m building a beamer-presentation template, and I would like to include a logo on the front of the slides. Although this could be achieved by including an image in the directory of the presentation, I would prefer not to have to create a new directory for each new presentation just for that one image.

有没有一种方法可以从包 resources 文件夹中检索相对文件路径,并让它在 LaTeX 投影仪模板中引用该位置?

Is there a way where I can retrieve the relative file path from within the package resources folder and have it reference that location in the LaTeX beamer template?

我尝试将图像与 .tex 模板一起放在资源文件夹中,但是当我尝试编织它时,出现 file not found 错误.>

I have tried placing the image in the resources folder along with the .tex template but when I try to knit it I get a file not found error.

推荐答案

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

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.

这篇关于在 R Markdown 模板中包含图像,而无需为模板创建新目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆