1

As far I know the longtable package allow to split a long table in multiple page. The problem is that my table is both long and large. I have 35 rows and 40 columns. How to split this table on multiples pages ?

Assuming that the package split at every 5 columns I should get a header for the first page : "Serie - Model1 - Model2 - Model3 - Model4 " and for the next page, the header should be similar to : "Serie - Model5 - Model6 - Model7 - Model8 "

For illustration purpose please find below my table with only the first 5 rows :

\begin{tabular}{rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr}
\toprule
 Serie & Model1 & Model2 & Model3 & Model4 & Model5 & Model6 & Model7 & Model8 & Model9 & Model10 & Model11 & Model12 & Model13 & Model14 & Model15 & Model16 & Model17 & Model18 & Model19 & Model20 & Model21 & Model22 & Model23 & Model24 & Model25 & Model26 & Model27 & Model28 & Model29 & Model30 & Model31 & Model32 & Model33 & Model34 & Model35 & Model36 & Model37 & Model38 & Model39 & Model40 \\
 \midrule
1     & -0.24(0.299) & -0.234(0.212) & NaN(<0.001) & -0.245(0.812) & -0.241(0.299) & -0.234(0.112) & -0.24(0.317) & -0.247(1.000) & -0.21(0.299) & -0.206(0.046) & -0.236(0.739) & -0.238(0.317) & 0.975(<0.001) & -0.204(0.013) & -0.226(0.317) & -0.216(0.317) & 0.978(<0.001) & -0.125(<0.001) & -0.156(<0.001) & -0.141(0.001) & 0.975(<0.001) & -0.204(0.016) & -0.227(0.317) & -0.216(0.317) & 0.975(<0.001) & -0.204(0.016) & -0.225(0.317) & -0.228(0.812) & 0.975(<0.001) & -0.206(0.016) & -0.22(0.299) & -0.215(0.317) & 0.974(<0.001) & -0.219(0.206) & -0.241(0.812) & -0.23(0.812) & 0.974(<0.001) & -0.212(0.132) & -0.241(0.812) & -0.231(0.812) \\
 2     & -0.0791(0.693) & -0.0833(0.720) & -0.0791(0.720) & -0.0858(0.989) & -0.0829(0.708) & -0.09(1.000) & -0.0826(0.709) & -0.0866(0.961) & -0.0191(<0.001) & -0.0405(0.010) & -0.0446(0.016) & -0.0746(0.649) & 0.986(<0.001) & -0.0257(0.037) & -0.0881(0.991) & -0.0828(0.953) & 0.989(<0.001) & 0.0256(0.041) & -0.0332(<0.001) & -0.0247(<0.001) & 0.986(<0.001) & -0.0253(0.033) & -0.086(0.818) & -0.0813(0.945) & 0.986(<0.001) & -0.0256(0.020) & -0.0867(0.649) & -0.0815(0.749) & 0.986(<0.001) & -0.026(0.016) & -0.0825(0.649) & -0.0826(0.950) & 0.986(<0.001) & -0.0406(0.080) & -0.0881(0.979) & -0.0852(0.989) & 0.986(<0.001) & -0.035(0.057) & -0.0883(0.991) & -0.0853(0.989) \\
 3     & -0.192(0.994) & -0.188(0.973) & -0.193(0.994) & -0.191(0.994) & -0.191(0.991) & 0.166(0.374) & -0.192(0.994) & -0.191(0.994) & -0.161(0.609) & -0.181(0.973) & -0.174(0.961) & -0.194(1.000) & 0.967(<0.001) & -0.113(0.005) & -0.188(0.980) & -0.152(0.827) & 0.969(<0.001) & -0.0659(<0.001) & -0.141(<0.001) & -0.126(<0.001) & 0.967(<0.001) & -0.113(0.010) & -0.187(0.980) & -0.169(0.945) & 0.967(<0.001) & -0.112(0.012) & -0.188(0.980) & -0.171(0.950) & 0.967(<0.001) & -0.113(0.022) & -0.19(0.994) & -0.144(0.243) & 0.967(<0.001) & -0.113(0.030) & -0.192(0.994) & -0.178(0.973) & 0.967(<0.001) & -0.114(0.032) & -0.192(0.973) & -0.177(0.949) \\
4     & -0.371(0.267) & -0.382(0.822) & -0.371(0.253) & -0.377(0.532) & -0.37(0.171) & -0.383(0.822) & -0.37(0.147) & -0.371(0.156) & -0.258(<0.001) & -0.289(0.002) & -0.335(<0.001) & -0.362(0.063) & 0.911(<0.001) & -0.285(<0.001) & -0.385(0.822) & -0.342(<0.001) & 0.912(<0.001) & -0.275(<0.001) & -0.366(0.063) & -0.372(0.115) & 0.911(<0.001) & -0.285(<0.001) & -0.385(0.822) & -0.388(0.822) & 0.911(<0.001) & -0.284(<0.001) & -0.386(0.822) & -0.356(0.411) & 0.911(<0.001) & -0.284(<0.001) & -0.385(0.802) & -0.356(<0.001) & 0.911(<0.001) & -0.292(<0.001) & -0.387(0.822) & -0.391(1.000) & 0.911(<0.001) & -0.292(<0.001) & -0.387(0.548) & -0.39(0.822) \\
 5     & -0.305(0.053) & -0.313(0.218) & -0.304(0.053) & -0.31(0.349) & -0.314(0.548) & -0.323(0.829) & -0.313(0.329) & -0.307(0.525) & -0.15(<0.001) & -0.199(<0.001) & -0.231(<0.001) & -0.284(0.003) & 0.832(<0.001) & -0.195(<0.001) & -0.304(0.010) & -0.299(0.029) & 0.832(<0.001) & -0.176(<0.001) & -0.294(0.012) & -0.288(0.003) & 0.832(<0.001) & -0.191(<0.001) & -0.3(0.005) & -0.296(0.006) & 0.832(<0.001) & -0.193(<0.001) & -0.304(0.010) & -0.303(0.135) & 0.832(<0.001) & -0.195(<0.001) & -0.31(0.124) & -0.3(0.046) & 0.831(<0.001) & -0.216(<0.001) & -0.328(0.548) & -0.321(0.829) & 0.831(<0.001) & -0.212(0.001) & -0.328(1.000) & -0.321(0.829)
\bottomrule
\end{tabular}%

(Ps : I can flip the matrix but the problem is the same with 40 columns and 35 rows..)

9
  • A simple solution would be to use A2 paper… :o)
    – Bernard
    Jul 19 '16 at 13:27
  • @Bernard Unfortunately it is not possible it is for my thesis ^^
    – Malick
    Jul 19 '16 at 13:28
  • I'm thinking about a solution, but longtable doesn't manage wide tables (I don't know any package doing that). I guess you'll have to split it into two or three tables (that you might number like table 1a, table 1b, &c.
    – Bernard
    Jul 19 '16 at 13:44
  • 1
  • 1
    anything's possible but I may not have time, no harm in adding to the question though, someone may answer. But to be honest I wouldn't do this. think of the reader, the chance that they can navigate a table that's rotated and automatically split on row and column boundaries into arbitrary page sized chunks is essentially nil. Compared to the work required to implement a programatic solution, the work required to refactor the table into smaller chunks based on semantically meaningful divisions that you can choose with subject knowledge is likely to be less and make a better result. Jul 19 '16 at 14:59
1

Based on David Carlisle comment and its answer in another post (https://tex.stackexchange.com/a/93810/44284) I succeed, the code is given below.

However, I finally follow David recommendation "to refactor the table into smaller chunks based on semantically meaningful divisions", it seems more appropriate.

%% Credit : David Carlisle 
\documentclass{article}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{array}
\usepackage{caption}
\newcounter{tablepage}
\makeatletter

% #1 no of pages
% #2 caption
% #3 table 
% table usesnormal tabular except
% Replace & by \thbreak after column(s) you want repeated.
% replace & by \tbreak at points you want page to break.
% must be a \tbreak before final \\
% any nested tabulars must be inside {} to hide the &
% \multicolumn is allowed but can not span a break.
% might want to replace \cleardoublepage by a cmmand to get onto left pf speread
% the tabular preamble needs as many columns (including heading columns) as the 
% page with the most columns.
\long\def\widesplit#1#2#3{%
\def\row{\rowz\c@tablepage}%
\cleardoublepage
\setcounter{tablepage}{0}%
\loop
\refstepcounter{tablepage}%
\noindent
\begin{minipage}{\columnwidth}\centering
 \ifnum\c@tablepage=\@ne
    \captionof{table}{#2}%
 \else
\captionof*{table}{#2 (page \thetablepage\ of #1)}%
 \fi
#3
\end{minipage}%
\clearpage
\ifnum#1>\c@tablepage
\repeat}

\begin{document}

\def\rowa#1\thbreak#2\tbreak#3\\{#1&#2\\}

\def\rowz#1{%
  \ifnum#1=\@ne
    \expandafter\rowa
  \else
    \expandafter\rowq\expandafter{\the\numexpr#1-1\expandafter\relax\expandafter}%
  \fi}

\def\rowq#1#2\thbreak#3\tbreak{\rowz{#1}#2\thbreak}
\centering
\footnotesize


\widesplit{4}{some boring numbers}{% 
\begin{tabular}{>\bfseries{l}rrrrrrrrrr}
    \row
     Serie \thbreak Model1 & Model2 & Model3 & Model4 & Model5 & Model6 & Model7 & Model8 & Model9 & Model10 \tbreak 
     Model11 & Model12 & Model13 & Model14 & Model15 & Model16 & Model17 & Model18 & Model19 & Model20 \tbreak
      Model21 & Model22 & Model23 & Model24 & Model25 & Model26 & Model27 & Model28 & Model29 & Model30 \tbreak
      Model31 & Model32 & Model33 & Model34 & Model35 & Model36 & Model37 & Model38 & Model39 & Model40  \tbreak\\[2ex]
      \row
      1     \thbreak -0.24(0.299) & -0.234(0.212) & NaN(<0.001) & -0.245(0.812) & -0.241(0.299) & -0.234(0.112) & -0.24(0.317) & -0.247(1.000) & -0.21(0.299) & -0.206(0.046) \tbreak
       -0.236(0.739) & -0.238(0.317) & 0.975(<0.001) & -0.204(0.013) & -0.226(0.317) & -0.216(0.317) & 0.978(<0.001) & -0.125(<0.001) & -0.156(<0.001) & -0.141(0.001) \tbreak 0.975(<0.001) & -0.204(0.016) & -0.227(0.317) & -0.216(0.317) & 0.975(<0.001) & -0.204(0.016) & -0.225(0.317) & -0.228(0.812) & 0.975(<0.001) & -0.206(0.016) \tbreak -0.22(0.299) & -0.215(0.317) & 0.974(<0.001) & -0.219(0.206) & -0.241(0.812) & -0.23(0.812) & 0.974(<0.001) & -0.212(0.132) & -0.241(0.812) & -0.231(0.812) \tbreak\\
        \row
       2     \thbreak -0.24(0.299) & -0.234(0.212) & NaN(<0.001) & -0.245(0.812) & -0.241(0.299) & -0.234(0.112) & -0.24(0.317) & -0.247(1.000) & -0.21(0.299) & -0.206(0.046) \tbreak
        -0.236(0.739) & -0.238(0.317) & 0.975(<0.001) & -0.204(0.013) & -0.226(0.317) & -0.216(0.317) & 0.978(<0.001) & -0.125(<0.001) & -0.156(<0.001) & -0.141(0.001) \tbreak 0.975(<0.001) & -0.204(0.016) & -0.227(0.317) & -0.216(0.317) & 0.975(<0.001) & -0.204(0.016) & -0.225(0.317) & -0.228(0.812) & 0.975(<0.001) & -0.206(0.016) \tbreak -0.22(0.299) & -0.215(0.317) & 0.974(<0.001) & -0.219(0.206) & -0.241(0.812) & -0.23(0.812) & 0.974(<0.001) & -0.212(0.132) & -0.241(0.812) & -0.231(0.812) \tbreak\\
         \row
        3   \thbreak -0.24(0.299) & -0.234(0.212) & NaN(<0.001) & -0.245(0.812) & -0.241(0.299) & -0.234(0.112) & -0.24(0.317) & -0.247(1.000) & -0.21(0.299) & -0.206(0.046) \tbreak
         -0.236(0.739) & -0.238(0.317) & 0.975(<0.001) & -0.204(0.013) & -0.226(0.317) & -0.216(0.317) & 0.978(<0.001) & -0.125(<0.001) & -0.156(<0.001) & -0.141(0.001) \tbreak 0.975(<0.001) & -0.204(0.016) & -0.227(0.317) & -0.216(0.317) & 0.975(<0.001) & -0.204(0.016) & -0.225(0.317) & -0.228(0.812) & 0.975(<0.001) & -0.206(0.016) \tbreak -0.22(0.299) & -0.215(0.317) & 0.974(<0.001) & -0.219(0.206) & -0.241(0.812) & -0.23(0.812) & 0.974(<0.001) & -0.212(0.132) & -0.241(0.812) & -0.231(0.812) \tbreak\\
          \row
          4     \thbreak -0.24(0.299) & -0.234(0.212) & NaN(<0.001) & -0.245(0.812) & -0.241(0.299) & -0.234(0.112) & -0.24(0.317) & -0.247(1.000) & -0.21(0.299) & -0.206(0.046) \tbreak
          -0.236(0.739) & -0.238(0.317) & 0.975(<0.001) & -0.204(0.013) & -0.226(0.317) & -0.216(0.317) & 0.978(<0.001) & -0.125(<0.001) & -0.156(<0.001) & -0.141(0.001) \tbreak 0.975(<0.001) & -0.204(0.016) & -0.227(0.317) & -0.216(0.317) & 0.975(<0.001) & -0.204(0.016) & -0.225(0.317) & -0.228(0.812) & 0.975(<0.001) & -0.206(0.016) \tbreak -0.22(0.299) & -0.215(0.317) & 0.974(<0.001) & -0.219(0.206) & -0.241(0.812) & -0.23(0.812) & 0.974(<0.001) & -0.212(0.132) & -0.241(0.812) & -0.231(0.812) \tbreak\\
           \row
          5    \thbreak -0.24(0.299) & -0.234(0.212) & NaN(<0.001) & -0.245(0.812) & -0.241(0.299) & -0.234(0.112) & -0.24(0.317) & -0.247(1.000) & -0.21(0.299) & -0.206(0.046) \tbreak
           -0.236(0.739) & -0.238(0.317) & 0.975(<0.001) & -0.204(0.013) & -0.226(0.317) & -0.216(0.317) & 0.978(<0.001) & -0.125(<0.001) & -0.156(<0.001) & -0.141(0.001) \tbreak 0.975(<0.001) & -0.204(0.016) & -0.227(0.317) & -0.216(0.317) & 0.975(<0.001) & -0.204(0.016) & -0.225(0.317) & -0.228(0.812) & 0.975(<0.001) & -0.206(0.016) \tbreak -0.22(0.299) & -0.215(0.317) & 0.974(<0.001) & -0.219(0.206) & -0.241(0.812) & -0.23(0.812) & 0.974(<0.001) & -0.212(0.132) & -0.241(0.812) & -0.231(0.812) \tbreak\\
 \end{tabular}}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.