Forums | OpenR
OpenR: R & Statistics
/
questions about the location of picture after knitting to pdf
03 April 2022, 12:03 PM
I use picture to show the results of code, but I find that the location of the picture is automatically adjusted after knitting to pdf. I guess it's due to the format requirement of pdf. How can I solve this issue?
03 April 2022, 4:12 PM
The simplest way is using cross-reference: number the picture, and mention it as "Figure x shows the code ....".
05 April 2022, 11:01 AM
Yes, sometimes it works. LaTeX tries inserting an image in a visually optimized place, but it might not be the place where you like.
22 April 2022, 9:34 AM
Hey guys, I am sorry that I forgot to update this question and you may try this method to solve the problem. In the header of the rmd file, you could add two lines:
header-includes:
\usepackage{float}
the header could be like :
title:
subtitle: "Word count: "
author: ""
numbersections: true
header-includes:
\usepackage{float}
output:
bookdown::word_document2: default
and in the chunk code for figure, you could set a parameter 'fig.pos="H"', like
```{r,echo=FALSE, fig.align='center', fig.pos="H"}
knitr::include_graphics('xxx.png')
```
Then the picture will be fixed.
23 April 2022, 10:18 AM
Thanks for sharing. More details could be found at: https://bookdown.org/yihui/rmarkdown-cookbook/figure-placement.html