首页 > 解决方案 > rticles 包中的 knitr::include_graphics 不起作用

问题描述

我正在使用 R rticles 包中的 Elsevier 模板在 Rstudio 中生成 pdf 文档。对于论文,我想包含一个 .png 图像。当我加载图像时

![text](images/framework.png)

一切正常,但是当我将其更改为等效的 knitr 命令时(我更喜欢它,因为它更容易设置无花果大小等)。

{r map, fig.cap="text"}
knitr::include_graphics("images/framework.png") 

我收到以下错误:

! Paragraph ended before \Gin@iii was complete.
<to be read again>

当我在 rmarkdown 中切换到 pdf 的标准输出设置时,output:pdf_documentknitr 选项确实有效,所以我猜这个问题一定与 rticles 包有关。我在互联网上查看并认为这可能与使用 \graphics 包而不是 \graphicx 乳胶包有关...... https://tex.stackexchange.com/questions/37650/paragraph-ended-before-giniii-was -在插入时完成图像与包含

我尝试在 yaml 中添加以下内容:

header-includes:
   - \usepackage{graphicx}

但错误仍然存​​在。

标签: rtemplatesr-markdown

解决方案


昨天我遇到了同样的问题,使用rticles::elsevier_articleand knitr::include_graphics

今天我找到了解决方案:dpi = NAinclude_graphics函数中使用:

{r map, fig.cap="text"}
knitr::include_graphics("images/framework.png", dpi = NA) 

但是,在组合两个图像并 out.width = '50%'在代码块中使用参数时,我仍然会遇到相同的错误:

{r map, fig.cap="text", out.width = '50%'}
knitr::include_graphics(c("img1", "img2"), dpi = NA) 

希望它仍然有用!


推荐阅读