8

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}
2
  • 1
    Maybe the tabu package allows this. It includes a lot of tricky features. Commented Jul 16, 2011 at 12:10
  • @Martin Scharrer: Thank you - tabu might help. However, I don't dare adding just another such complex package to my preamble, as it could have effects on many other tables as well. In that case I would just set the column-number as a variable in my command and define it for each longtable. Commented Jul 16, 2011 at 12:29

1 Answer 1

6

try this:

\makeatletter
\def\LongtableFooter{%
  \multicolumn{\LT@cols}{r}{to be continued on following page}\\}
\makeatother
2
  • thank you, looks promising, however if I replace my command with your lines in my example, it is printed only in the last footer and before the bottomrule - what am I doing wrong? (see/try changed minimal example in my question) Commented Jul 16, 2011 at 13:30
  • 1
    @Martin: I had a nice bug ... :-) \def\LongtableFooter#1{ was the problem, I forgot to delete the #1 in my example. Now corrected
    – user2478
    Commented Jul 16, 2011 at 13:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .