How to insert a regular image (jpeg / png) from a piece with knitr

I want to insert an image at the beginning of the text using a block of code, not markdown. I use the Tufte output: rmarkdown::tufte_handout handout template output: rmarkdown::tufte_handout , and when I insert it right after the YAML header, but before the TOC, for example:

 \centering ![width='100%'](./cropped-banner_efpt.jpg) \raggedright \tableofcontents \clearpage 

The image then covers the main body. I know that with chunks there is an option so that the chunk spans the entire page by putting fig.fullwidth = TRUE in the block header, but I am a bit stuck with this, since I am not generating any graph from the data, and I don’t know how for simple posting the image from inside the piece.

Another thing is that when I set toc: true in the YAML header, the image only appears after the toc is inserted - that’s why I insert the toc with the latex command.

Thanks for your suggestions.

+5
source share
1 answer

If the picture is not generated from R-code, you can use knitr::include_graphics() to insert it into the document, for example

 ```{r echo=FALSE, out.width='100%'} knitr::include_graphics('./cropped-banner_efpt.jpg') ``` 
+24
source

Source: https://habr.com/ru/post/1246209/


All Articles