R,knitr不尊重块和文本的顺序 [英] R, knitr doesn't respect order of chunks and text

查看:93
本文介绍了R,knitr不尊重块和文本的顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想象一下我编织了这个Rnw文件:

Imagine I knit 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}

这是一个简单的示例,仅显示一些文本和三个表.

It's a simple example that just prints some text and three tables.

奇怪的是,它不尊重我在代码中编写的顺序. 我明白了(两个pdf页面的侧面图)

Strangely it doesn't respect the order of what I've written on my code. I get this (sideview of the two pdf pages)

但是"Table3"文本应该出现在table3本身之前和table2之后,而文本"just some text"应该出现在文档的末尾.

But "Table3" text should appear before the table3 itself and after table2, and the text "just some text" should appear at the very end of the document.

如果我在其中写几行,则会中断这些行.

If I write several lines there it breaks the lines.

我知道,如果桌子不适合放置在某个地方,则必须将其移至下一页,但应该使用以下文本和桌子来完成.

I understand that if a table doesn't fit on a place it must be moved to the next page but so should be done with the following text and tables.

我还观察到,在其他示例中,某些表格不合适时会随机重新分配.

I've also observed that in other examples some tables are reallocated randomly when they don't fit well.

如何防止编织器执行此操作? 我不知道是针织问题还是乳胶.

How can I prevent knitr from doing this? I don't know whether is a knitr problem or latex.

我正在使用Texlive 2015,Rstudio,R 3.2.3和Windows 10以及涉及的所有软件包的最新版本.

I'm using Texlive 2015, Rstudio, R 3.2.3 and Windows 10 and the latest version of all packages involved.

推荐答案

默认情况下,print.xtable()会生成LaTeX \table{...}环境,该环境被定义为浮动对象.参见`?print.xtable并尝试例如

By default print.xtable() produces a LaTeX \table{...} environment, which is defined as a floating object. See `?print.xtable and try e.g.

<<example2,results='asis', echo=FALSE>>=
print(xtable(mydata, caption="Table2"),floating=FALSE)
@

(未经测试...)

或者您可以尝试table.placement="H";您可能需要\usepackage{float}(请参阅tex.stackexchange.com中的此问题 ).

alternatively you could try table.placement="H"; you may need \usepackage{float} (see this question from tex.stackexchange.com).

(也是未经测试的...)

(also untested ...)

这篇关于R,knitr不尊重块和文本的顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆