Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

header on each page of big table of xtable?

How do you put on a big table of xtable the table header on each page?, So that is easier to read the table the table between pages.

I use the following in Sweave:

test.big<- xtable(test,label="table",caption='test')
align(test.big) <- "|c|c|c|c|l|c|c|c|"
print(test.big,tabular.environment='longtable',include.colnames = TRUE,floating=FALSE)

Thanks for your answers

like image 460
ricardo Avatar asked Dec 16 '22 19:12

ricardo


2 Answers

I think a better answer for this question is provided here: Column names on each page with xtable in Sweave

What if you want to edit your table in R? The solution above edits the output, so you won't need to add those lines in your longtable code manually. Thus this works better:

print(test.big, tabular.environment='longtable', include.colnames = TRUE,
floating=FALSE, add.to.row = list(pos = list(0), command = "\\hline \\endhead "))

Note that you can add several arguments in your add.to.row list:

print(test.big, tabular.environment='longtable', include.colnames = TRUE,
floating=FALSE, list(pos = list(seq(1,nrow(get(groups[i])), by = 2), 0),
command = c("\\rowcolor[gray]{.95} ","\\hline \\endhead ")))

You'll have to add this to your Sweave file:

\usepackage{colortbl}

This produces gray filling on every second row & header for each page.

like image 54
Mikko Avatar answered Jan 22 '23 14:01

Mikko


The longtable (LaTeX) package specification can be found at that URL. The section of code in the examples whose output appears on pages 2 and 3 is in section 8 and I have reproduced bit of it below:

\caption[]{(continued)}\\ 
\hline\hline 
\multicolumn{2}{@{*}c@{*}}% 
{This part appears at the top of every other page}\\ 
\textbf{First}&\textbf{Second}\\ 
\hline\hline 
\endhead 

When they say on "every other page", they mean every page other than the first, which had a different header. If the xtable call is not working out of the box without any editing, then you should first check that you have the longtable package specified in your LaTeX preamble:

\usepackage{longtable}
like image 31
IRTFM Avatar answered Jan 22 '23 13:01

IRTFM