xtable周围的空白

时间:2014-02-28 12:43:35

标签: r knitr sweave xtable

我正在尝试使用knitr在文本正文中插入一个小表。我不确定这是针织/扫掠问题还是xtable,但我在桌子周围得到了大量的空白。以下是表格设置为5cm的输出示例:

enter image description here

当我在knitr代码中调整表格的宽度时,图形标题会发生变化,但表格和空格保持不变。这是表格设置为2 cm的输出:

enter image description here

如何控制xtable周围的空白?这是我正在使用的代码:

\documentclass{article}
\usepackage{wrapfig}
\usepackage{float}

\begin{document}

TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT    TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT \par

<<test,echo=FALSE>>=
library(xtable)
## Make some data
School <- c("School A", "School B", "School C", "School D")
N <- c(59, 101, 69, 124)

df <- data.frame (School,N)

x <- xtable(df)
@

\begin{wraptable}[12]{l}[5pt]{5cm}
<<print,results='asis',echo=FALSE>>=
print (x, table.placement = getOption("xtable.table.placement", "H"))
@
\caption{Number of Responses}
\end{wraptable}

TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT


\end{document}

1 个答案:

答案 0 :(得分:4)

你在一个table中放置一个浮动的wraptable,就像一只吃着较小的鲨鱼的大鲨鱼。如果你只保留tabular,事情就会奏效。

print (x, table.placement = getOption("xtable.table.placement", "H"),
     floating=FALSE)

wraptable视为table的替代。