# help

2 messages
 Hi: I am going through some of the xtable examples and I can't make the one below work. I need to create a longtable on the fly keeping the column headers for all the pages and I thought this example could give some ideas on how to do it. I am using Sweave and xtable to create my tables and graphics. I wonder if someone could tell me what's wrong. Thanks ## Not run: \begin{small} \setlongtables \begin{longtable}{ <>= cat(paste(c('c', rep('cc', 34/2-1), 'c'), collapse='@{\hspace{2pt}}')) @ } \hline \endhead \hline \endfoot <>= library(xtable) set.seed(2345) res <- matrix(sample(0:9, size=34*90, replace=TRUE), ncol=34, nrow=90) xres <- xtable(res) digits(xres) <- rep(0, 35) addtorow <- list() addtorow$pos <- list() addtorow$pos[[1]] <- c(seq(4, 40, 5), seq(49, 85, 5)) addtorow$pos[[2]] <- 45 addtorow$command <- c('\vspace{2mm} \n', '\newpage \n') print(xres, add.to.row=addtorow, include.rownames=FALSE, include.colnames=FALSE, only.contents=TRUE, hline.after=NULL) @ \end{longtable} \end{small} ## End(Not run) Felipe D. Carrillo   Supervisory Fishery Biologist   Department of the Interior   US Fish & Wildlife Service   California, USA ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
 Unfortunately a little long Try this (I have used Miktex 2.7 on win XP and R 2.8 for this) I have not gone into the detail of the first chunk I just created the header strings in R and copied to make the Sweave file lines With a little thought it can be done I suppose ## Sweave script \documentclass[10pt,a4paper,landscape]{article} \usepackage[T1]{fontenc} \usepackage{textcomp} \usepackage{times} \usepackage[left=0.5in,right=0.5in,top=1.0in,bottom=1.0in,includefoot]{geometry} \usepackage{dcolumn} \usepackage{booktabs} \usepackage{longtable} \setlength{\parindent}{0pt} % BEGIN DOCUMENT \begin{document} \begin{small} \begin{longtable}[34]{rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr} % if want different first 1 \toprule \addlinespace[5pt] 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 & 16 & 17 & 18 & 19 & 20 & 21 & 22 & 23 & 24 & 25 & 26 & 27 & 28 & 29 & 30 & 31 & 32 & 33 & 34 \\ \addlinespace[3pt] \midrule \addlinespace[5pt] \endfirsthead % all table headers (if not first different use \toprule instead on the next line) \midrule \addlinespace[5pt] 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 & 16 & 17 & 18 & 19 & 20 & 21 & 22 & 23 & 24 & 25 & 26 & 27 & 28 & 29 & 30 & 31 & 32 & 33 & 34 \\ \addlinespace[3pt] \midrule \addlinespace[5pt] \endhead % last footer \addlinespace[5pt] \bottomrule \endlastfoot % other footers \addlinespace[5pt] \multicolumn{33}{r}{Continued next page}\\ \addlinespace[3pt] \midrule \endfoot % <>=    library(xtable)    set.seed(2345)    res <- matrix(sample(0:9, size=34*90, replace=TRUE), ncol=34, nrow=90)    x <- apply(res,1,function(x) paste(paste(x,collapse= " & "), "\\\\ \n") )    for (j in seq_along(x) ) cat(x[j]) @ \end{longtable} \end{small} % END DOCUMENT \end{document} # end Sweave Regards Duncan Mackay Department of Agronomy and Soil Science University of New England ARMIDALE NSW 2351 Email (home): [hidden email] At 06:30 9/01/2009, you wrote: >Hi: >I am going through some of the xtable examples and I can't make the one >below work. I need to create a longtable on the fly keeping the column >headers for all the pages and I thought this example could give some ideas >on how to do it. I am using Sweave and xtable to create my tables and >graphics. I wonder if someone could tell me what's wrong. Thanks > >## Not run: >\begin{small} >\setlongtables >\begin{longtable}{ ><>= >cat(paste(c('c', rep('cc', 34/2-1), 'c'), collapse='@{\hspace{2pt}}')) >@ >} >\hline >\endhead >\hline >\endfoot ><>= >library(xtable) >set.seed(2345) >res <- matrix(sample(0:9, size=34*90, replace=TRUE), ncol=34, nrow=90) >xres <- xtable(res) >digits(xres) <- rep(0, 35) >addtorow <- list() >addtorow$pos <- list() >addtorow$pos[[1]] <- c(seq(4, 40, 5), seq(49, 85, 5)) >addtorow$pos[[2]] <- 45 >addtorow$command <- c('\vspace{2mm} \n', '\newpage \n') >print(xres, add.to.row=addtorow, include.rownames=FALSE, >include.colnames=FALSE, only.contents=TRUE, hline.after=NULL) >@ >\end{longtable} >\end{small} >## End(Not run) > > >Felipe D. Carrillo >Supervisory Fishery Biologist >Department of the Interior >US Fish & Wildlife Service >California, USA > >______________________________________________ >[hidden email] 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. ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.