knitr::include_graphics in rticles package does not work

Viewed 579

I am using the Elsevier template from the R rticles package to produce a pdf document in Rstudio. For the paper I want to include a .png image. When I load the image with

![text](images/framework.png)

things work fine but when I change this to the equivalent knitr command (which I prefer because it is easier to set fig size etc).

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

I get the following error:

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

When I switch to standard output setting for pdf in rmarkdown output:pdf_document the knitr option does work so I guess the problem must be related to the rticles package. I looked on the internet and think it might be related to using the \graphics package instead of the \graphicx latex package... https://tex.stackexchange.com/questions/37650/paragraph-ended-before-giniii-was-complete-while-inserting-image-with-inclu

I tried adding the following in yaml:

header-includes:
   - \usepackage{graphicx}

but the error remains.

1 Answers

yesterday I just had the same problem, using rticles::elsevier_article and knitr::include_graphics.

Today I found the solution: use dpi = NA in include_graphics function:

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

However, I still get the same error when combining two images and using out.width = '50%' parameter in the code chunk:

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

Hope it's still useful!

Related