[R] xtable - caption missing with float=FALSE

Marc Schwartz marc_schwartz at me.com
Wed Aug 10 21:27:46 CEST 2011


On Aug 10, 2011, at 2:02 PM, Zev Ross wrote:

> Hi,
> 
> For some reason I'm finding that my table caption is disappearing if I print xtable output with the floating argument set to FALSE. Below is a very simple Sweave file that produces two tables the first has no caption and the second has a caption (if you want to see it http://www.zevross.com/temp/test.pdf).
> 
> Does anyone know what I can do to fix this?
> 
> Zev
> 
> (I'm using Windows 7, 64 bit, R 2.12.2)
> 
> % begin Rnw file
> 
> \documentclass[a4paper]{article}
> 
> \begin{document}
> 
> <<results=tex, echo=FALSE>>=
> library(xtable)
> 
> atable<-data.frame(a=1:10, b=rnorm(10))
> print(xtable(atable, caption="FLOAT"), floating=FALSE)
> print(xtable(atable, caption="NO FLOAT"), floating=TRUE)
> @
> 
> \end{document}
> 
> 
> Sweave("test.Rnw")
> texi2dvi("test.tex", pdf=TRUE, clean=TRUE)
> 

Hi,

If you compare the output of the two commands, the 'floating = TRUE' variant places the tabular environment within a table environment. The tabular environment does not support the \caption command, table does, hence no caption if the tabular is not contained within a float (floating = FALSE).

HTH,

Marc Schwartz



More information about the R-help mailing list