Adjusting cell height in tables wider than a full page

Suppose there is a table too wide to fit on a page. What you can do in this case is to print the table on multiple pages, such that it can be seen side-by-side, by using multiple table environments and separating these with page breaks.

Given these column definitions:

\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}p{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}p{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}p{#1}}


Table code for a 2-page wide table is akin to:

\begin{longtable}{|L{80pt}|L{80pt}|}
\hline
\hline
value 11 this is a much longer value which causes issues by overflowing into another line and misaligning this table with the other table & value 12 \\
value 21 & value 22 \\
\hline
\end{longtable}
\pagebreak
\begin{longtable}{|L{80pt}|L{80pt}|}
\hline
\hline
value 13 & value 14 \\
value 23 & value 24 \\
\hline
\end{longtable}


Note that the values are variable. In essence, 'any reasonably long text' could be inside each cell.

This works and aligns as long as within the set of all the values there are no values which span multiple lines, e.g. no cells with line breaks. However, as soon as there are cells with line breaks, these line breaks will only appear in their respective table.

How does one go about aligning the tables? E.g. in table i, column j set its column height to be at least the maximum of the column heights of all the tables for column j.

• Are you sure this design of a table should be implemented? Is there no other option (e.g. sidewaystable) for you? – TeXnician May 4 '17 at 12:08
• it is impossible to see from your fragment (or even run your fragment) ut why do you need the columns to be 80pt wide? just making that value woudl work for the text shown – David Carlisle May 4 '17 at 13:24
• Please fix your example so that it demonstrates the issue. Your text describes "cells with line breaks" being the problem but you give no indication of the definition of L column nor show any cells with a line break. Do you mean forced line breaks (from \newline ?) or automatic line breaks from long text? Your example should be complete from \documentclass to \end{docuemnt} and demonstrate the issue. – David Carlisle May 4 '17 at 13:27
• one last question, why are you using longtable if you are ending each table within one page and forcing a page break outside the table? – David Carlisle May 4 '17 at 13:29
• The question does not concern 'this specific table' but rather 'ANY' table. You can suppose that the TeX code is machine-generated, and the table contents as well as no. of columns, no. of rows, and row/column widths are variables. I could make the example a really large table that demonstrates the desync issues but I don't want solutions that only fix that example (by say adding manual line breaks). – aphid May 4 '17 at 14:46

You can create a two page tabular and display half at a time using \adjustbox. Figuring out where the gap is could pose a problem. I also threw in some code to start the two pages on a even page.

BTW, I am not familiar with column type L, so used p instead.

\documentclass{article}
\usepackage{afterpage}
\usepackage{lipsum}% MWE only

\newsavebox{\twopage}

\newcommand{\evenpage}{\ifodd\value{page}\afterpage{\evenpage}%
\else
\newpage
\newpage
\fi}

\begin{document}
\savebox{\twopage}{\begin{tabular}
{|p{80pt}|p{80pt}|@{\hspace{2\tabcolsep}}|p{80pt}|p{80pt}|}
\hline
\hline
value 11 & value 12 & value 13 & value 14 \\
value 21 & value 22 & value 23 & value 24 \\
\hline
\end{tabular}}%
\evenpage
\lipsum[1-8]
\end{document}


I thought I would try to make this more like a table, including a caption split over two pages.

\documentclass{article}
\usepackage{afterpage}
\usepackage{lipsum}% MWE only
\usepackage{blindtext}% MWE only
%\usepackage{showframe}% debugging tool
\usepackage{caption}

\newsavebox{\twopage}
\newsavebox{\twopagecaption}
\newlength{\twopagecaptionht}

\makeatletter
{\newcommand\makecaption[2]{%
{\captionlabelfont #1}%
{\caption@iflf\captionlabelfont\relax\caption@lsep}%
{\captiontextfont
\caption@ifstrut
{\vrule\@height\ht\strutbox\@width\z@}%
{}%
\nobreak\hskip\z@skip % enable hyphenation
\caption@tfmt{#2}%
\caption@ifstrut
{\ifhmode\@finalstrut\strutbox\fi}%
{}%
}%
}}%
{}

\newcommand{\splitcaption}[2][\empty]% #1 = short caption (optional), #2 = caption
{\setbox\twopagecaption=\vbox{\parindent=0pt
\refstepcounter{table}%
\ifx\empty#1\relax
{\protect\numberline{\thetable}{\ignorespaces #2}}%
\else
{\protect\numberline{\thetable}{\ignorespaces #1}}%
\fi
\let\vskip=\@gobble
\@ifundefined{makecaption}{}{\let\@makecaption=\makecaption}%
\@makecaption{\fnum@table}{\ignorespaces #2}%
\par}}
\makeatother

\newcommand{\evenpage}{\clearpage
\ifodd\value{page}\afterpage{\evenpage}%
\else
\noindent\begin{minipage}[c][\textheight][c]{\textwidth}
\vskip\abovecaptionskip
\twopagecaptionht=\dimexpr \ht\twopagecaption + \dp\twopagecaption\relax
\dimen0=\dimexpr 0.5\twopagecaptionht + 0.5\baselineskip\relax
\setbox0=\vsplit\twopagecaption to \dimen0
\dimen0=\dimexpr \ht\twopagecaption + \dp\twopagecaption\relax
\ifdim\twopagecaptionht<\dimen0 \twopagecaptionht=\dimen0\fi
\vbox to \twopagecaptionht {\unvbox0\vfill}%
\global\twopagecaptionht=\twopagecaptionht
\end{minipage}\par
\noindent\begin{minipage}[c][\textheight][c]{\textwidth}
\vskip\abovecaptionskip
\vbox to \twopagecaptionht {\unvbox\twopagecaption\vfill}%
\end{minipage}%
\fi}

\begin{document}
\listoftables

\savebox{\twopage}{\begin{tabular}
{|p{80pt}|p{80pt}|@{\hspace{2\tabcolsep}}|p{80pt}|p{80pt}|}
\hline

• I think I understand how to extend this to three, four, etc. pages as well; by replacing the 0.5\width argument by x * 0.333\width, 0.25\width, and so on. E.g. the 4th page on a 6-page wide table would use 0.5\width and 0.667\width as its left- and right- clip boundaries. Remains getting rid of the artifacts at the table edge. But I think using the more detailed lines from the booktabs package should do the trick. (e.g. \cmidrule and friends). – aphid May 4 '17 at 15:52