[R] longtable and Sweave
Marc Schwartz
marc_schwartz at comcast.net
Tue Sep 18 19:31:51 CEST 2007
On Mon, 2007-09-17 at 12:26 +0200, Delphine Fontaine wrote:
> Dear Sweave-users,
>
> I want to print listing using sweave. Because my tables are very big, I use
> the longtable option. But, is it possible to recall the first line of the
> table (e.g the colnames line) on each new page ?
> Thanks for your help.
>
> Delphine
Strictly speaking, it's not an Sweave issue but a LaTeX markup issue.
Depending upon how you are generating your LaTeX output, there are ways
of specifying table headers and footers, and to differentiate how they
look on the first/last page versus the middle pages.
The easiest way, may be to use either the xtable()/print.xtable()
functions in David Dahl's 'xtable' package or the latex() function in
Frank Harrell's Hmisc package. Both have options to output your object
using longtable.
If you are coding this by hand, you need to review the longtable
documentation, paying attention to the use of the \endfirsthead,
\endhead, \endfoot and \endlastfoot tags to define, respectively, the
first page header, the remaining page headers, the footer for all but
the last page and the last page footer. These sections precede the
actual tabular content.
As an example:
begin{longtable}{lrr}
\caption[This is a longtable]{This is a longtable} \\
\toprule
\textbf{Column 1} & \textbf{Column 2} & \textbf{Column 3} \\
\midrule \\
\endfirsthead
\caption{This is a longtable (continued)} \\
\toprule
\textbf{Column 1} & \textbf{Column 2} & \textbf{Column 3} \\
\midrule \\
\endhead
\bottomrule
\endfoot
\bottomrule
\endlastfoot
Line 1 & Data 1 & Data 1 \\
Line 2 & Data 2 & Data 2 \\
Line 3 & Data 3 & Data 3 \\
\end{longtable}
Note that you do not have to use the \endfirsthead and \endlastfoot tags
if these are to be the same for all pages. You would only use the
\endhead and \endfoot tags in that case.
HTH,
Marc Schwartz
More information about the R-help
mailing list