Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
1  
Maybe the tabu package allows this. It includes a lot of tricky features. –  Martin Scharrer Jul 16 '11 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. –  Martin Jul 16 '11 at 12:29

1 Answer 1

up vote 4 down vote accepted

try this:

\makeatletter
\def\LongtableFooter{%
  \multicolumn{\LT@cols}{r}{to be continued on following page}\\}
\makeatother
share|improve this answer
    
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) –  Martin Jul 16 '11 at 13:30
    
@Martin: I had a nice bug ... :-) \def\LongtableFooter#1{ was the problem, I forgot to delete the #1 in my example. Now corrected –  Herbert Jul 16 '11 at 13:49
    
excellent! Thank you very much! –  Martin Jul 16 '11 at 13:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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