图片和文字的显示顺序与我的预期不同

Images and text coming out in a different order to how I expected

我最初的问题是试图让标题显示在 pdf 输出中,我想我现在已经找到了解决方法。但是在这个过程中,我的测试markdown文件又抛出了一个我不明白的问题。

我有一个看起来完全像这样的 rmarkdown 文件:

---
title: "Untitled"
author: "Nicole Avison"
date: "Monday, March 23, 2015"
output:
  pdf_document:
    number_sections: true
    fig_caption: yes
---
# Title 1  

![Image 1 caption](Images/picture1.png)

Text...  

# Title 2  

![Image 2 caption](Images/picture2.png)

# Title 3  

Some text here  

![Image 3 caption](Images/picture3.png)

Some more text here

当我在 R Studio 中单击 'knit pdf' 时,pdf 输出的顺序与我在 rmarkdown 文件中写入的顺序不同:

1 Title 1
[Image 1]
Figure 1: Image 1 caption
Text...
2 Title 2
3 Title 3
Some text here
Some more text here
[Image 2]
Figure 2: Image 2 caption
[Image 3]
Figure 3: Image 3 caption

这是不是因为我尝试了让字幕正常工作的方式,而且它有点像我记得的旧更改?或者这是我在做的有趣的事情?

当我将更改放入我的原始正确文档中以便标题显示(他们这样做)时,我也有这种奇怪的顺序更改:(不过在那种情况下只有最后的标题,其他的在正确的地方。

我认为这可能更像是一个 LaTex 问题。你的标题应该没问题,但 LaTex 说它不能将两个图像放在同一个第一页上,所以它将第二个图像放在页面上,然后标题就变得不稳定了。如果您只打算编译为 pdf,请在需要的地方编写原始 tex 代码。我在下面提供了一个简单的例子。请注意,它确实不能解决问题,但它可以让您更好地控制 object 放置(例如 \begin{figure} 之后的 [h!] 试图强制放置图形)。您还可以在 \includegraphics 的宽度参数中控制图形宽度(0.75 表示将图像缩小为全文宽度的 75%。抱歉,如果这不完整,但我希望它有所帮助。

---
title: "Untitled"
author: "Nicole Avison"
date: "Monday, March 23, 2015"
output:
  html_document: default
  pdf_document:
    fig_caption: yes
    number_sections: yes
---
# Title 1  

![Image 1 caption](image1.jpg)

Text...  

# Title 2  

\begin{figure}[h!]
\includegraphics[width=0.75\textwidth]{image2.jpg}
\caption{Image 2 caption}
\end{figure}

# Title 3  

Some text here  

![Image 3 caption](image3.jpg)

Some more text here