【问题标题】:knitr::include_graphics in rticles package does not workrticles 包中的 knitr::include_graphics 不起作用
【发布时间】:2020-03-18 12:42:52
【问题描述】:

我正在使用 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 output:pdf_document 中切换到 pdf 的标准输出设置时,knitr 选项确实有效,所以我猜这个问题一定与 rticles 包有关。我在互联网上查看并认为这可能与使用 \graphics 包而不是 \graphicx 乳胶包有关...... https://tex.stackexchange.com/questions/37650/paragraph-ended-before-giniii-was-complete-while-inserting-image-with-inclu

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

header-includes:
   - \usepackage{graphicx}

但错误仍然存​​在。

【问题讨论】:

    标签: r templates r-markdown


    【解决方案1】:

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

    今天找到了解决办法:在include_graphics函数中使用dpi = NA

    {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) 
    

    希望它仍然有用!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-12-03
      • 2021-10-10
      • 2018-04-19
      • 1970-01-01
      • 2017-04-17
      • 2021-07-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多