Qin Zhu
Qin Zhu

Reputation: 331

Image size control in Rmarkdown pdf generation with latex

I'm using Rmarkdownv2 to generate a pdf file with some local images. But it seems that the image was converted to a larger size with lower resolution in the rendered pdf, compared to the html. The code I'm currently using for the image is something like: ![alt text](figures/fig1.png)

Is there any way to control the image size in the pdf? I also tried

pdf_document: fig_height: 1 fig_width: 2

But that didn't work. Thanks in advance.

Upvotes: 2

Views: 806

Answers (1)

Yihui Xie
Yihui Xie

Reputation: 30104

You can use the development version of knitr (>= v1.11.22) and the include_graphics() function, e.g.

```{r out.width='70%'}
knitr::include_graphics('figures/fig1.png')
```

If you want a figure caption, just use the chunk option fig.cap = 'A figure caption.'

Upvotes: 4

Related Questions