8

For the appendix of my Ph. D. thesis I need to typeset some very big tables containing raw data. They have about 30 columns and might have enough lines to not fit vertically on one (double)page.

Is there a package which allows to create a table which covers a whole double page (in width), so columns 1-15 on left page and columns 16-30 on right page and that even with one or more pagebreaks?

I know about longtable, but I didn't find an option which allows that.

The lines of both tables should be vertically aligned, however it might be a good idea to repeat the ("characteristic") first column also on the right page for clear identification of each line.

(Sure I could also split it up into more than one table but I would prefer to have all data for each measured part in one line.)

Further practical questions:

  • are there recommendations for such a case?

e.g.

  • would one caption on the first left page be enough?
  • normally I would make my tables with the booktabs package and avoid horizontal lines between "normal" table lines, however in this case it could be helpful to help the eye group the lines, maybe by groups of 3 (that would make sense for my data9 to help the eye follow the lines...
  • how can I reduce the outer margins (only) for those large tables to use most of the pagewidth?
6
  • 1
    I don't think that there is such a package, which can split the columns over two pages. I personally would write a small script (e.g. Perl) to auto-generate the code (two separate tabulars) from the data. If they don't fit on one page each you need to adjust the script to generate more pages. I know it's some effort. Jun 27, 2011 at 8:48
  • 1
    Indeed, AFAIK there isn't such a package. Personally, I'd write two separate documents for the table, and use pdfpages to include the table.
    – Leo Liu
    Jun 27, 2011 at 11:07
  • @Leu Liu: Thanks for your comment - that's what I did not, however the vertical adjustment on the right page (without caption) remains a problem (see my comment on egreg's answer). Jul 1, 2011 at 23:27
  • @Martin Scharrer: thanks, that's in general a good idea, but too difficult for a Puggle (=non-programming person) like me. ;-) I did it by hand in a nasty multi-step-process exporting the tables from my statistics software to MS Excel, rearranging them and then using the Excel2LaTeX-VBA-Plugin to export the LaTeX-Code which for sure had to be adjusted to work as expected.. [But if I had written any code to do that, it would have taken longer, I suppose, and - taking into account my programming skills - I could not be sure that any of the numbers is at the right place afterwards...] Jul 1, 2011 at 23:30
  • 1
    See this answer here for a semi-automatic solution: Table and multi-page
    – Alan Munn
    Jul 2, 2011 at 16:26

2 Answers 2

4

I think that the only feasible option is to split the data into 2n parts:

  • first part, columns 1-15, rows 1-24, \newpage
  • second part, columns 16-30, rows 1-24, \newpage
  • third part, columns 1-15, rows 24-48, \newpage
  • fourth part, columns 16-30, rows 24-48, \newpage
  • ...

Twenty-four rows is just to put some number. If the data and the header row are homogeneous in height, they should align perfectly.

For the caption, it can go on the left page, but I suggest to set it into a \vbox with prescribed height:

\newcommand{\mycaption}[1]{\vbox to 3\baselineskip{
   \vfill\captionof{table}{#1}\vfill}}

where 3 is a number bigger than the number of lines in the caption. For the right page you can say

\newcommand{\fakecaption}{\vbox to 3\baselineskip{}}

and insert \fakecaption after the \newpage; \captionof requires the caption package.

The margins can be overridden either with \newgeometry of the geometry package or simply by inserting each "subtable" inside \makebox[\textwidth]{}.

A possible implementation

\documentclass[a4paper,twoside]{book}
\usepackage{caption}

\newlength{\leftcaptionht}
\newsavebox{\tablebox}
\newcommand{\lefttable}[1]{%
  \setbox\tablebox=\vbox{\medskip\captionof{table}{#1}}
  \setlength{\leftcaptionht}{\ht\tablebox}%
  \box\tablebox}

\newenvironment{doubletable}
  {\newpage\ifodd\value{page}\null\newpage\fi\centering}{\newpage}
\newenvironment{widetabular}
  {\begin{lrbox}{\tablebox}\begin{tabular}}
  {\end{tabular}\end{lrbox}\makebox[\textwidth]{\usebox{\tablebox}}}

\newcommand{\righttable}{\newpage\vbox to\leftcaptionht{}}

\begin{document}

text 

\begin{doubletable}
\lefttable{This is a caption}

\begin{widetabular}{ll}
a column long enough to go over  & a column long enough to arrive over the right margin\\
a column & a column long enough to arrive near the right margin\\
a column & a column long enough to arrive near the right margin\\
a column & a column long enough to arrive near the right margin\\
a column & a column long enough to arrive near the right margin\\
a column & a column long enough to arrive near the right margin\\
a column & a column long enough to arrive near the right margin\\
a column & a column long enough to arrive near the right margin\\
a column & a column long enough to arrive near the right margin\\
a column & a column long enough to arrive near the right margin\\
a column & a column long enough to arrive near the right margin\\
a column & a column long enough to arrive near the right margin\\
a column & a column long enough to arrive near the right margin\\
a column & a column long enough to arrive near the right margin\\
a column & a column long enough to arrive near the right margin\\
\end{widetabular}

\righttable

\begin{widetabular}{ll}
a column & a column long enough to arrive near the right margin\\
a column & a column long enough to arrive near the right margin\\
a column & a column long enough to arrive near the right margin\\
a column & a column long enough to arrive near the right margin\\
a column & a column long enough to arrive near the right margin\\
a column & a column long enough to arrive near the right margin\\
a column & a column long enough to arrive near the right margin\\
a column & a column long enough to arrive near the right margin\\
a column & a column long enough to arrive near the right margin\\
a column & a column long enough to arrive near the right margin\\
a column & a column long enough to arrive near the right margin\\
a column & a column long enough to arrive near the right margin\\
a column & a column long enough to arrive near the right margin\\
a column & a column long enough to arrive near the right margin\\
a column & a column long enough to arrive near the right margin\\
\end{widetabular}

\end{doubletable}

\begin{doubletable}

\lefttable{This is a caption that occupies more than one line and so has to wrap, so that we 
can show that the alignment is correct}

\begin{widetabular}{ll}
a column long enough to go over  & a column long enough to arrive over the right margin\\
a column & a column long enough to arrive near the right margin\\
a column & a column long enough to arrive near the right margin\\
a column & a column long enough to arrive near the right margin\\
a column & a column long enough to arrive near the right margin\\
a column & a column long enough to arrive near the right margin\\
a column & a column long enough to arrive near the right margin\\
a column & a column long enough to arrive near the right margin\\
a column & a column long enough to arrive near the right margin\\
a column & a column long enough to arrive near the right margin\\
a column & a column long enough to arrive near the right margin\\
a column & a column long enough to arrive near the right margin\\
a column & a column long enough to arrive near the right margin\\
a column & a column long enough to arrive near the right margin\\
a column & a column long enough to arrive near the right margin\\
\end{widetabular}

\righttable

\begin{widetabular}{ll}
a column & a column long enough to arrive near the right margin\\
a column & a column long enough to arrive near the right margin\\
a column & a column long enough to arrive near the right margin\\
a column & a column long enough to arrive near the right margin\\
a column & a column long enough to arrive near the right margin\\
a column & a column long enough to arrive near the right margin\\
a column & a column long enough to arrive near the right margin\\
a column & a column long enough to arrive near the right margin\\
a column & a column long enough to arrive near the right margin\\
a column & a column long enough to arrive near the right margin\\
a column & a column long enough to arrive near the right margin\\
a column & a column long enough to arrive near the right margin\\
a column & a column long enough to arrive near the right margin\\
a column & a column long enough to arrive near the right margin\\
a column & a column long enough to arrive near the right margin\\
\end{widetabular}

\end{doubletable}

\end{document}

If you want a caption on the right pages, it's sufficient to define \righttable differently:

\newcommand{\righttable}{\newpage\vbox to\leftcaptionht{\medskip
  \noindent(Table \thetable{} (continued)}}

(or something similar).

The suggestion is to add rows to the tables until they fit on the page and then start a new pair.

4
  • Thanks for your suggestion! I decided to split the table and typeset it page by page in a second pdf document and then include the pages with \includegraphics. Your solution for the vertical alignment is interesting. Is there a way to directly determine the real height of the caption on the left side and use this value on the right side for a \vspace? For a caption with 2 lines, 3*baselineskip is nearly perfect, just a little bit too much. Jul 1, 2011 at 23:25
  • thank you for the additional example! That looks very promising - I'll try it out later. Jul 2, 2011 at 13:17
  • Thanks for your help! It works great, as long as the height of the table fits on the page. But it fails, if the height of the table is too big, then the caption for the left table is on the left page and the table itself lands on the right page.. Can you help me fix that? Jul 2, 2011 at 23:35
  • p.s. would it be possible to add in the placeholder for the caption on the right page something like "continuation of table on the left page" (I'm not sure how to say that in English correctly) Jul 3, 2011 at 0:52
3

you can create the table with ConTeXt, it can split tabulars also in the horizontal direction. The created pdf can then be inserted into your document if you need to run it with pdflatex

4
  • thanks, that's interesting. I knew nothing about ConTeXtand a first quick google search tells me that it might be too complicated to dive in just for some tables. But it is good to know that there seems to be a "built-in" a solution elsewhere. Jul 2, 2011 at 12:50
  • @Martin: I posted an example here, but didn't find the message
    – user2478
    Jul 2, 2011 at 13:11
  • thanks to Alan Munn's comment above, I've not only found the dpfloatpackage which might help for aligning 2 tables on a double page, but there is also your example for ConTeXt : tex.stackexchange.com/questions/8959/table-and-multi-page/… Jul 2, 2011 at 19:31
  • Maybe it would be good to link to your other answer from this one? (That is, link to the one with the example in it.)
    – cfr
    Jan 2, 2016 at 22:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .