Forums | OpenR

OpenR: R & Statistics /
questions about the location of picture after knitting to pdf


Zhongzheng Mao's profile picture
Posts: 8

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?

Peng Zhao's profile picture
Posts: 128

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 ....".

Huanzhi Gong's profile picture
Posts: 11

04 April 2022, 4:13 PM

Maybe you can try to change the size of the picture. 

Peng Zhao's profile picture
Posts: 128

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.

Zhongzheng Mao's profile picture
Posts: 8

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.

Edits to this post:
Peng Zhao's profile picture
Posts: 128
6 results