Is it possible to define a multicolumn{}{}{}
-command, which automatically spans all columns of a table?
For my longtables I want to use a command defined in the preamble, which typesets at the right lower edge (raggedleft) a message, that the table will be continued on the following page.
As my longtables have different numbers of columns, I don't know how to define that general command. Is there a counter which reads the number of columns for the actual table and could be used?
edit: I found in the manual of the longtable package that there is an internal counter \LT@cols
, but I don't see how I could use it for the multicolumn-command – I even am not able to print its value in the document.
edit 3: with Herbert's code it works.
\makeatletter
\def\LongtableFooter{%
\multicolumn{\LT@cols}{r}{\scriptsize to be continued on following page}\\}
\makeatother
Example:
(remark: as the second longtable in the example has only 4 columns, the command with \multicolumn{5}
naturally failed.)
\documentclass[]{scrbook}
\usepackage{booktabs, longtable}
%\newcommand{\LongtableFooter}{\multicolumn{5}{r}\mbox{to be continued on following page}}
\makeatletter
\def\LongtableFooter{%
\multicolumn{\LT@cols}{r}{\scriptsize to be continued on following page}\\}
\makeatother
\begin{document}
here comes the table with the pagebreak
\vspace{0.6\textheight}
\begin{longtable}{p{2cm}p{2cm}p{2cm}ll}
\toprule
A & B & C & D & E\\
\midrule
\endfirsthead
\mbox{table continued from last page}\\
\toprule
A & B & C & D\\
\midrule
\endhead
%\bottomrule
\LongtableFooter
\endfoot
\bottomrule
\endlastfoot
a & b & c & d\\
\midrule
a & b & c & d\\
& b & c & d\\
& b & c & d\\*
\midrule
a & b & c & d\\
& b & c & d\\
& b & c & d\\*
\midrule
a & b & c & d\\
& b & c & d\\
& b & c & d\\*
\midrule
a & b & c & d\\
& b & c & d\\
& b & c & d\\
\midrule
a & b & c & d\\
& b & c & d\\
& b & c & d\\
\midrule
a & b & c & d\\
& b & c & d\\
& b & c & d\\
\end{longtable}
And here it fails, as there are only 4 columns:
\begin{longtable}{p{2cm}p{2cm}p{2cm}ll}
\toprule
A & B & C & D\\
\midrule
\endfirsthead
\mbox{table continued from last page}\\
\toprule
A & B & C & D\\
\midrule
\endhead
%\bottomrule
\LongtableFooter
\endfoot
\bottomrule
\endlastfoot
a & b & c & d\\
& b & c & d\\
& b & c & d\\
& b & c & d\\
& b & c & d\\
& b & c & d\\*
\midrule
a & b & c & d\\
& b & c & d\\
& b & c & d\\*
\midrule
a & b & c & d\\
& b & c & d\\
& b & c & d\\*
\midrule
a & b & c & d\\
& b & c & d\\
& b & c & d\\*
\midrule
a & b & c & d\\
& b & c & d\\
& b & c & d\\*
\midrule
a & b & c & d\\
& b & c & d\\
& b & c & d\\*
\midrule
a & b & c & d\\
& b & c & d\\
& b & c & d\\
\midrule
a & b & c & d\\
& b & c & d\\
& b & c & d\\
\midrule
a & b & c & d\\
& b & c & d\\
& b & c & d\\
\midrule
a & b & c & d\\
& b & c & d\\
& b & c & d\\
\end{longtable}
\end{document}
\end{document}
Best Answer
try this: