# How can I create a table that spans across the width of two vertical (and opposite) A4 pages?

I have a large (wide) table to typeset. I usually use the code below for my tables which enables me to specify the width of each column in the table. However, it is up to me to make sure that the sum of the column widths fit on a page.

\documentclass[12pt, a4paper]{article}
\usepackage{booktabs, array}

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

\begin{document}
\begin{table}
\begin{tabular}{C{2cm}  C{2cm} C{2cm} C{2cm}  C{2cm} C{2cm}}
\toprule

~ & \textbf{Column 1} & \textbf{Column 2} & \textbf{Column 3} & \textbf{Column 4} & \textbf{Column 5}  \\
\textbf{Row 1} & Text (1,1) & Text (1,2) & Text (1,3) & Text (1,4) & Text (1,5)  \\
\textbf{Row 2} & Text (2,1) & Text (2,2) & Text (2,3) & Text (2,4) & Text (2,5)  \\
\textbf{Row 3} & Text (3,1) & Text (3,2) & Text (3,3) & Text (3,4) & Text (3,5)  \\
\textbf{Row 4} & Text (4,1) & Text (4,2) & Text (4,3) & Text (4,4) & Text (4,5)  \\
\textbf{Row 5} & Text (5,1) & Text (5,2) & Text (5,3) & Text (5,4) & Text (5,5)  \\
\textbf{Row 6} & Text (6,1) & Text (6,2) & Text (6,3) & Text (6,4) & Text (6,5)  \\

\bottomrule

\end{tabular}
\caption{This is a table}
\end{table}
\end{document}


I would like to create a very wide table that spans across the width of 2 vertical A4 pages

(I am writing a document using 2 sides of a page and I would like the left corner of my table to be on an even page number and the right corner of the table on the opposite page).

There should therefore not be any right margin on the left page and no left margin on the right page so that the table is continuous across the width of the two A4 pages.

Is this possible?

-
How to include a picture over two pages, left part on left side, right on right (for books)? is a similar idea; adapting it to table isn't trivial though... – cmhughes Apr 13 '13 at 14:59

I started with my answer at How do I create 6 parallel texts aligned by paragraph, with 3 texts on each page? as a baseline, but had to make a number of changes.

On the easier side, I don't have to worry about row entries of different heights for this OP's query. But on the negative side, I had to significantly rewrite code to handle 10 or more column entries (since #10 doesn't work). To that end, I didn't pass different column entries as arguments, but wrote my own tab parsing code, so that the row could be entered as if it were a tabular row.

I still used Herbert's code snippet for processing tabular tokens within a \whiledo, and I added a snippet from Stephan Lehmke for starting the table on an even page number when in twoside mode.

As a bonus feature, not only do I allow the code to be broken across left/right pages, but it can be broken vertically as well, for extra long tables. The syntax is \newtwopagetable to initialize the process. Then, individual rows are added with \tenbyrow{} where the argument is a &-separated list of ten entries (it is minor rewrite for other column number entries). Finally, when all the data is entered in this fashion, you have two options:

\newtwopagetable{caption}


will output the whole table over two pages; or

\maketwopagetable[4]{caption}
\maketwopagetable[4]{caption}


will split the two-sided table into vertical pieces, as well, shown above as four rows on the first double page, and four rows on the second double page.

Here is the source code:

\documentclass[twoside]{article}% TABLE CLEARS TO EVEN PAGE
%\documentclass{article}% TABLE CLEARS TO NEXT PAGE
\usepackage{booktabs, array}
\usepackage{ifthen}
\usepackage{etoolbox}

\makeatletter%%%%%%%%%%% My own tab parsing code

\newcounter{TABcellindex@}

\def\postTAB{#2}%
\setcounter{TABcellindex@}{0}%
\stepcounter{TABcellindex@}%
\expandafter\processTAB\postTAB&\\%
\ifthenelse{\equal{\preTAB}{}}{%
}{%
\expandafter\protected@edef\csname #1\alph{TABcellindex@}\endcsname{%
\preTAB}%
}%
}%
% \#1TABcells GIVES HOW MANY TAB COLUMNS WERE PROCESSED
%  \expandafter\xdef\csname #1TABcells\endcsname{\arabic{TABcellindex@}}%
}

\def\processTAB#1&#2\\{%
\protected@edef\preTAB{#1}%
\protected@edef\postTAB{#2}%
}

\makeatother%%%%%%%%%%% END My own tab parsing code

\makeatletter%%%%%%%%%%% Herbert's tabular token code
\newcounter{tabindex}
\newtoks\@tabtoks
\@tabtoks\expandafter{\the\@tabtoks\stepcounter{tabindex}#1}}
\newcommand*\resettabtoks{\@tabtoks{}}
\newcommand*\synctabindex[1]{\setcounter{tabindex}{\value{#1}}}
\newcommand*\printtabtoks{\the\@tabtoks}
\makeatother%%%%%%%%%%% END Herbert's tabular token code

\makeatletter%%%%%%% Lehmke's \cleartoleftpage
\def\cleartoleftpage{\clearpage\if@twoside \ifodd\c@page
\hbox{}\newpage\if@twocolumn\hbox{}\newpage\fi\fi\fi}
\makeatother
\makeatother%%%%%%%% END Lehmke's \cleartoleftpage

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

\newcounter{sptstartrow}
\newcounter{sptendrow}
\newcounter{entries}

\newcommand\newtwopagetable{%
\setcounter{sptendrow}{0}%
\setcounter{entries}{0}%
\cleartoleftpage%
}

\makeatletter
\newcommand\tenbyrow[1]{%
\stepcounter{entries}%
}
\makeatother
\newcounter{index}
\newcommand\maketwopagetable[2][\theentries]{%
\setcounter{sptstartrow}{\thesptendrow}%
\ifthenelse{\thesptstartrow > 1}%
{\def\conttext{}}%
\ifthenelse{\thesptendrow > \theentries}{\setcounter{sptendrow}{\theentries}}{}%
\clearpage
\setcounter{index}{\thesptstartrow}%
\synctabindex{index}
\resettabtoks%
\whiledo{\theindex < \thesptendrow}{%
\stepcounter{index}%
\csname entryX\roman{tabindex}Xa\endcsname &
\csname entryX\roman{tabindex}Xb\endcsname &
\csname entryX\roman{tabindex}Xc\endcsname &
\csname entryX\roman{tabindex}Xd\endcsname &
\csname entryX\roman{tabindex}Xe\endcsname
\\%
}%
}%
\begin{table}
\centering
\begin{tabular}{C{2cm}  C{2cm} C{2cm} C{2cm} C{2cm}}
\toprule

\printtabtoks%

\bottomrule
\end{tabular}%
\caption{#2 (left half\conttext)}
\end{table}%
\clearpage
\setcounter{index}{\thesptstartrow}%
\synctabindex{index}
\resettabtoks%
\whiledo{\theindex < \thesptendrow}{%
\stepcounter{index}%
\csname entryX\roman{tabindex}Xf\endcsname &
\csname entryX\roman{tabindex}Xg\endcsname &
\csname entryX\roman{tabindex}Xh\endcsname &
\csname entryX\roman{tabindex}Xi\endcsname &
\csname entryX\roman{tabindex}Xj\endcsname
\\%
}%
}%
\begin{table}
\centering
\begin{tabular}{C{2cm}  C{2cm} C{2cm} C{2cm} C{2cm}}
\toprule

\printtabtoks%

\bottomrule
\end{tabular}%
\caption{#2 (right half\conttext)}
\end{table}%
}

\begin{document}
\newtwopagetable
\tenbyrow%
{~ & \textbf{Column 1} & \textbf{Column 2} & \textbf{Column 3} &
\textbf{Column 4} & \textbf{Column 5} & \textbf{Column 6} &
\textbf{Column 7} & \textbf{Column 8} & \textbf{Column 9}}
\tenbyrow%
{\textbf{Row 1} & Text (1,1) & Text (1,2) & Text (1,3) & Text (1,4)
& Text (1,5) & Text (1,6) & Text (1,7) & Text (1,8) & Text (1,9)}
\tenbyrow%
{\textbf{Row 2} & Text (2,1) & Text (2,2) & Text (2,3) & Text (2,4)
& Text (2,5) & Text (2,6) & Text (2,7) & Text (2,8) & Text (2,9)}
\tenbyrow%
{\textbf{Row 3} & Text (3,1) & Text (3,2) & Text (3,3) & Text (3,4)
& Text (3,5) & Text (3,6) & Text (3,7) & Text (3,8) & Text (3,9)}
\tenbyrow%
{\textbf{Row 4} & Text (4,1) & Text (4,2) & Text (4,3) & Text (4,4)
& Text (4,5) & Text (4,6) & Text (4,7) & Text (4,8) & Text (4,9)}
\tenbyrow%
{\textbf{Row 5} & Text (5,1) & Text (5,2) & Text (5,3) & Text (5,4)
& Text (5,5) & Text (5,6) & Text (5,7) & Text (5,8) & Text (5,9)}
\tenbyrow%
{\textbf{Row 6} & Text (6,1) & Text (6,2) & Text (6,3) & Text (6,4)
& Text (6,5) & Text (6,6) & Text (6,7) & Text (6,8) & Text (6,9)}
\tenbyrow%
{\textbf{Row 7} & Text (7,1) & Text (7,2) & Text (7,3) & Text (7,4)
& Text (7,5) & Text (7,6) & Text (7,7) & Text (7,8) & Text (7,9)}
\maketwopagetable{This is a table}

\newtwopagetable
\setcounter{entries}{8}% THIS IS TO FOOL LaTeX INTO THINKING I RE-ENTERED THE TABLE DATA
\maketwopagetable[4]{This is a vertically split table}
\maketwopagetable[4]{This is a vertically split table}

\end{document}


Here is the full table output on a double page:

While here is the table, split width and lengthwise, as output over the next four pages. Note that the (left/right half, continued) commentary is provided by \maketwopagetable, and is not part of the user's captioning argument.

-
This looks like it may be a very good solution to a similar problem which I'm having, but my table has a rather absurd number of columns (55 or so), and I wanted to check what I should modify in the code to accommodate those; I assume I'll define the tabular environment to reflect the structure I'm using, but is there anything else I've overlooked? Thanks! – Erika Mar 14 at 12:53
@Erika I have not looked at my code in a while. If I had to do it over again, I might replace \roman{tabindex} with \romannumeral\value{tabindex}. But to be quite honest, without seeing an attempt at a wider table, I'm not sure what might break on it. Best wishes and let me know if you succeed. – Steven B. Segletes Mar 14 at 13:40