I'm trying to insert a small table in a body of text using knitr. The I'm not sure if it's a knitr/sweave problem or with xtable but I get a ton of whitespace around the table. Here is an example of the output with the table set to 5cm:
When I adjust the width of the table in the knitr code the figure caption changes but the table and whitespace stays the same. Here is the output with the table set to 2 cm:
How do I control the whitespace around an xtable? Here is the code I'm using:
\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}
You are putting a floating table
within a wraptable
, which is like a big shark eating a smaller one. If you keep the tabular
only, things work.
print (x, table.placement = getOption("xtable.table.placement", "H"),
floating=FALSE)
Think of wraptable
as a replacement for table
.