Rmarkdown Image Skips Ahead of Text

对着背影说爱祢 提交于 2019-12-22 06:31:13

问题


I am putting together an Rmarkdown PDF document with the following YAML settings:

---
output: 
  pdf_document:
    fig_caption: true 
    fig_crop: true
    toc_depth: 3
  header-includes:
  - \usepackage{hyperref}
 ---

Within the body of the document I've inserted a few PNG images, using the following syntax

Paragraph 1..........

![Caption](path/image.png)

Paragraph 2....

And when the document is rendered, the image appears as expected within the text, between Paragraph 1 and Paragraph 2. However, I am getting some unpredictable results where the rendered image appears after Paragraph 2 in some cases and I can't manage to solve it.


回答1:


I have run into the same problem. It appears if you wrap the image in "paragraph" tags, the image will be in-line with the text.

Paragraph 1...

<p>
![](image.png)
</p>

Paragraph 2...



回答2:


When tackling similar issues, I've used \FloatBarrier (from the placeins package) to control positioning. I'm not the most experienced knitr rmarkdown LaTeX user, but I've had success with that before.

Basically, the images "float"; you can control what the can't float past by inserting a barrier. That description is crude, but you might find the technique effective.




回答3:


One option is to add

\newpage

to act in a similar way as the Floatbarrier. It is not to elegant but seems to work.

For greater clarity consider the example from above:

Paragraph 1..........

![Caption](path/image.png)

Paragraph 2....

To avoid the image to move in front of the second paragraph, you could do the following:

Paragraph 1..........

![Caption](path/image.png)

\newpage

Paragraph 2....



回答4:


There is no correct answer to this.

  1. Try adding fig.show='hold' to keep your images where they should be
  2. The paragraphs might be skipped because Latex will try and fit the text/images with least space.

I sorted my issue out using (1) and to "work with" (2), you can use \pagebreak in an appropriate position depending on what is before and after paragraphs 1 and 2.

This can be done only after seeing the pdf result, by better fitting of the image in question into potentially a next page (more space). Of course, it would also mean adding the page break elsewhere (e.g before or after any of the p1, p2 or the image).




回答5:


\newline seems to work.

History and Overview of R

![R programming](Images/R.PNG)\newline



来源:https://stackoverflow.com/questions/34145865/rmarkdown-image-skips-ahead-of-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!