longtable example

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

longtable example

Felipe Carrillo
Hi:
Could someone try to run this example? I can't make it work.
## Not run:
 \begin{small}
 \setlongtables
 \begin{longtable}{
 <<results=tex,fig=FALSE>>=
 cat(paste(c('c', rep('cc', 34/2-1), 'c'), collapse='@{\hspace{2pt}}'))
 @
 }
 \hline
 \endhead
 \hline
 \endfoot
 <<results=tex,fig=FALSE>>=
 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.
Reply | Threaded
Open this post in threaded view
|

Re: longtable example

Dieter Menne
Felipe Carrillo <mazatlanmexico <at> yahoo.com> writes:

>
> Could someone try to run this example? I can't make it work.

It would be better if you would show a complete sample; the error could be
in the header part, and chances are better to get a reply when other do
not have to guess what to add.

>  \begin{small}
>  \setlongtables
>  \begin{longtable}{
>  <<results=tex,fig=FALSE>>=
>  cat(paste(c('c', rep('cc', 34/2-1), 'c'), collapse='@{\hspace{2pt}}'))
>  @
>  }
>  \hline


The { after \begin{longtable} looks suspicious.

Dieter

______________________________________________
[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.
Reply | Threaded
Open this post in threaded view
|

Re: longtable example

Felipe Carrillo
This is what I got.

\documentclass[11pt]{article}
\usepackage{longtable,lscape}
\usepackage{accents}
\usepackage[usenames,dvipsnames]{color} % load all the colors
\title{\color{Blue}How to transfer column names and add captions to pages in document}
\begin{document}
\maketitle
I am using Sweave and MikTex to generate my report but I am having problems with a table
that has 52 rows. I have no problem creating the 'longtable' but since my table is created dynamically,
I don't know how to transfer the column names to the second page of the PDF. I can name my column
names manually but since the table is created on the fly I wonder if there's a way that the column
headers from the first page be transferred automatically to the second or third pages and also have
captions on the header and footer of the pages ( something like 'Continued on next page').
Here's an example
<<tab.R,echo=FALSE,results=tex>>=
x <- matrix(rnorm(1000), ncol = 10)
x.big <- data.frame(x)
x.big <- xtable(x,label='big',align="c|cccccccccc|",caption='Example of longtable spanning several pages')
print(x.big,tabular.environment='longtable',latex.environments=c("center"),include.rownames=FALSE,floating=FALSE)
@
I want to add the column headers from the first page to the rest of the pages
and the caption 'Continued' to the top of each page. Thanks
\end{document}



--- On Thu, 1/8/09, Dieter Menne <[hidden email]> wrote:

> From: Dieter Menne <[hidden email]>
> Subject: Re: [R] longtable example
> To: [hidden email]
> Date: Thursday, January 8, 2009, 11:32 PM
> Felipe Carrillo <mazatlanmexico <at> yahoo.com>
> writes:
>
> >
> > Could someone try to run this example? I can't
> make it work.
>
> It would be better if you would show a complete sample; the
> error could be
> in the header part, and chances are better to get a reply
> when other do
> not have to guess what to add.
>
> >  \begin{small}
> >  \setlongtables
> >  \begin{longtable}{
> >  <<results=tex,fig=FALSE>>=
> >  cat(paste(c('c', rep('cc', 34/2-1),
> 'c'), collapse='@{\hspace{2pt}}'))
> >  @
> >  }
> >  \hline
>
>
> The { after \begin{longtable} looks suspicious.
>
> Dieter
>
> ______________________________________________
> [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-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: longtable example

Dieter Menne

Felipe Carrillo wrote
This is what I got.

\documentclass[11pt]{article}
\usepackage{longtable,lscape}
\usepackage{accents}
\usepackage[usenames,dvipsnames]{color} % load all the colors
\title{\color{Blue}How to transfer column names and add captions to pages in document}
...
The example you provided did not work, because you forgot the library(xtable).
I cannot help you with xtable because I normally use latex in Hmisc; see below

Dieter

-----------------

\documentclass[11pt]{article}
\usepackage{longtable,lscape}
\usepackage[usenames,dvipsnames]{color} % load all the colors
\title{\color{Blue}How to transfer column names and add captions to pages in document}
\begin{document}
\maketitle
<<tab.R,echo=FALSE,results=tex>>=
library(Hmisc)
#library(xtable)
x <- matrix(rnorm(1000), ncol = 10)
x.big <- data.frame(x)
latex(x.big,"",file="",longtable=TRUE, dec=2,
  caption='Example of longtable spanning several pages')
#x.big <- xtable(x,label='big',align="c|cccccccccc|",
#  caption='Example of longtable spanning several pages')
#print(x.big,tabular.environment='longtable',
#  latex.environments=c("center"),include.rownames=FALSE,floating=FALSE)
@
I want to add the column headers from the first page to the rest of the pages
and the caption 'Continued' to the top of each page. Thanks
\end{document}


Reply | Threaded
Open this post in threaded view
|

Re: longtable example

Felipe Carrillo
Thanks Dieter:
It's exactly what I want. Thanks a lot for you help. One thing that I noticed though, when I generated my pdf all the pages had different numbers of rows, for example page 1 had 24 rows,second page 15 rows,third page 2 rows of data. Is that something that can be controlled with pagebreaks? I am reading about the 'latex' function right now in some cases I will need to print some tables in 'landscape',so is there an option to landscape that particular page instead of just landscaping the table?



--- On Fri, 1/9/09, Dieter Menne <[hidden email]> wrote:

> From: Dieter Menne <[hidden email]>
> Subject: Re: [R] longtable example
> To: [hidden email]
> Date: Friday, January 9, 2009, 10:01 AM
> Felipe Carrillo wrote:
> >
> > This is what I got.
> >
> > \documentclass[11pt]{article}
> > \usepackage{longtable,lscape}
> > \usepackage{accents}
> > \usepackage[usenames,dvipsnames]{color} % load all
> the colors
> > \title{\color{Blue}How to transfer column
> names and add captions to pages
> > in document}
> > ...
> >
>
> The example you provided did not work, because you forgot
> the
> library(xtable).
> I cannot help you with xtable because I normally use latex
> in Hmisc; see
> below
>
> Dieter
>
> -----------------
>
> \documentclass[11pt]{article}
> \usepackage{longtable,lscape}
> \usepackage[usenames,dvipsnames]{color} % load all the
> colors
> \title{\color{Blue}How to transfer column names and
> add captions to pages in
> document}
> \begin{document}
> \maketitle
> <<tab.R,echo=FALSE,results=tex>>=
> library(Hmisc)
> #library(xtable)
> x <- matrix(rnorm(1000), ncol = 10)
> x.big <- data.frame(x)
> latex(x.big,"",file="",longtable=TRUE,
> dec=2,
>   caption='Example of longtable spanning several
> pages')
> #x.big <-
> xtable(x,label='big',align="c|cccccccccc|",
> #  caption='Example of longtable spanning several
> pages')
> #print(x.big,tabular.environment='longtable',
> #
> latex.environments=c("center"),include.rownames=FALSE,floating=FALSE)
> @
> I want to add the column headers from the first page to the
> rest of the
> pages
> and the caption 'Continued' to the top of each
> page. Thanks
> \end{document}
>
>
>
> --
> View this message in context:
> http://www.nabble.com/longtable-example-tp21356712p21377352.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [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-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: longtable example

Dieter Menne
Felipe Carrillo <mazatlanmexico <at> yahoo.com> writes:


> One thing that I noticed though, when I generated my pdf
> all the pages had different numbers of rows, for example page 1 had 24
rows,second page 15 rows,third page 2
> rows of data. Is that something that can be controlled with pagebreaks?

I darkly remember having seen something like that before, it has to do with
some block processing in latex (I mean tex/latex, not the R function);

As a workaround, try

lines.page=10000

But don't expect miracles, I am not sure it will help.

Dieter

______________________________________________
[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.