问题
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..........

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>

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

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

\newpage
Paragraph 2....
回答4:
There is no correct answer to this.
- Try adding
fig.show='hold'
to keep your images where they should be - 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
\newline
来源:https://stackoverflow.com/questions/34145865/rmarkdown-image-skips-ahead-of-text