On 28/10/2011 2:40 PM, Trevor Davies wrote:> I have found that I like having my captions and labels in my latex document
> rather than having them contained in my xtable output file (I haven't
fully
> gone to sweave yet).
The remark in the parens is the problem here. Use Sweave.
Duncan Murdoch
> I know I can do something like this by using the
> 'only.contents' argument in xtable. Unfortunately, the
only.contents
> argument also removes the \begin{tabular}{rrrrrr}& \end{tabular} (in
the
> example below) of the table. This means that I have to go look up each
> table to determine the number of columns.
>
> Is there a more automated way that I am missing? i.e only.contents but with
> tabular headers (but not \begin{table})?
> Thank you.
>
> CODE:
>
> ## Demonstrate include.rownames, include.colnames,
> ## only.contents and add.to.row arguments
> set.seed(2345)
> res<- matrix(sample(0:9, size=6*9, replace=TRUE), ncol=6, nrow=9)
> xres<- xtable(res)
> digits(xres)<- rep(0, 7)
> addtorow<- list()
> addtorow$pos<- list()
> addtorow$pos[[1]]<- c(0, 2)
> addtorow$pos[[2]]<- 4
> addtorow$command<- c('\vspace{2mm} \n', '\vspace{10mm}
\n')
> print(xres, add.to.row=addtorow, include.rownames=FALSE,
> include.colnames=TRUE, only.contents=TRUE, hline.after=c(0, 0, 9, 9))
>
>
> Output (only.contents=TRUE)
> % latex table generated in R 2.13.2 by xtable 1.6-0 package
> % Fri Oct 28 11:38:10 2011
> 1& 2& 3& 4& 5& 6 \\
> space{2mm}
> \hline
> \hline
> 1& 7& 6& 6& 5& 9 \\
> 1& 1& 1& 5& 7& 7 \\
> space{2mm}
> 7& 3& 9& 8& 0& 5 \\
> 0& 0& 4& 1& 5& 2 \\
> space{10mm}
> 4& 1& 8& 5& 7& 1 \\
> 2& 4& 5& 9& 5& 4 \\
> 6& 3& 3& 5& 5& 8 \\
> 7& 6& 1& 0& 7& 6 \\
> 4& 4& 8& 8& 3& 2 \\
> \hline
> \hline
>
> Output (only.contents=FALSE)
>
> % latex table generated in R 2.13.2 by xtable 1.6-0 package
> % Fri Oct 28 11:39:23 2011
> \begin{table}[ht]
> \begin{center}
> \begin{tabular}{rrrrrr}
> 1& 2& 3& 4& 5& 6 \\
> space{2mm}
> \hline
> \hline
> 1& 7& 6& 6& 5& 9 \\
> 1& 1& 1& 5& 7& 7 \\
> space{2mm}
> 7& 3& 9& 8& 0& 5 \\
> 0& 0& 4& 1& 5& 2 \\
> space{10mm}
> 4& 1& 8& 5& 7& 1 \\
> 2& 4& 5& 9& 5& 4 \\
> 6& 3& 3& 5& 5& 8 \\
> 7& 6& 1& 0& 7& 6 \\
> 4& 4& 8& 8& 3& 2 \\
> \hline
> \hline
> \end{tabular}
> \end{center}
> \end{table}
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.