据我所知,longtable 包允许将长表拆分为多个页面。问题是我的表是两个都又长又大。我有 35 行和 40 列。如何将此表拆分到多个页面上?
假设包每 5 列拆分一次,我应该获得第一页的标题:"Serie - Model1 - Model2 - Model3 - Model4 "
而对于下一页,标题应该类似于:
"Serie - Model5 - Model6 - Model7 - Model8 "
为了说明目的,请参阅下表,其中仅包含前 5 行:
\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}%
(附言:我可以翻转矩阵,但问题仍然相同,有 40 列和 35 行。)
答案1
根据 David Carlisle 的评论及其在另一篇文章中的回答(https://tex.stackexchange.com/a/93810/44284) 我成功了,代码如下所示。
不过,我最终还是按照David的建议“根据语义上有意义的划分将表重构为更小的块”,这似乎更合适。
%% 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\\}
\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}