Imagine I embed this Rnw file:
\documentclass{article} \begin{document} Table1 <<example,results='asis', echo=FALSE>>= require(xtable) nn <- 15 mydata <- data.frame(A=1:nn,C=nn:1, C=runif(nn), D=rnorm(nn)) xtable(mydata, caption="Table1") @ Table2 <<example2,results='asis', echo=FALSE>>= xtable(mydata, caption="Table2") @ Table3 <<example3,results='asis', echo=FALSE>>= xtable(mydata, caption="Table3") @ \begin{obeylines} Just some text \end{obeylines} \end{document}
This is a simple example that just prints text and three tables.
Oddly, this does not match the order of what I wrote in my code. I get this (two page pdf review) 
But the text "Table3" should appear before table 3 itself and after table2, and the text "just some text" should appear at the very end of the document.
If I write several lines, it breaks the lines.
I understand that if the table does not fit in place, it needs to be moved to the next page, but this should be done with the following text and tables.
I also noticed that in other examples, some tables are redistributed randomly when they do not fit well.
How can I prevent knitr from doing this? I do not know if the problem is with knit or latex.
I use Texlive 2015, Rstudio, R 3.2.3 and Windows 10 and the latest version of all the packages involved.