# multicolumn in longtable with span dependant on number of columns

How can I use \multicolumn in a longtable environment to span all columns except for one? The \LT@cols counter is probably the way to go. However, doing arithmetics in LaTeX seems somewhat unconventional. Related to multicolumn-command which automatically uses all columns of the table?. What's needed is "\LT@cols minus one".

-
You can use \numexpr\LT@cols-1. Without a MWE, answers too will be trivial ;) – Harish Kumar Mar 29 '14 at 10:29
Welcome to TeX.SX! Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – Christian Hupfer Mar 29 '14 at 10:46

You can use \numexpr\LT@cols-1 and define your own multicolumn command like

\makeatletter
\def\mymc#1#2{%
\multicolumn{\numexpr\LT@cols-1}{#1}{#2}%              %%#1 = alignment, #2 = content
}
\makeatother


and use it like

\mymc{r}{abc}


Full code:

\documentclass[]{scrbook}

\usepackage{booktabs, longtable}

\makeatletter
\def\mymc#1#2{%
\multicolumn{\numexpr\LT@cols-1}{#1}{#2}%
}
\makeatother

\begin{document}

\begin{longtable}{p{2cm}p{2cm}p{2cm}ll}

\toprule
A & B & C & D & E\\
\midrule

\mbox{table continued from last page}\\
\toprule
A & B & C & D\\

\midrule
%\bottomrule
\endfoot
\bottomrule
\endlastfoot

\mymc{r}{abc} & d\\
\midrule
a & \mymc{c}{bcd}\\
& b & c & d\\
& b & c & d\\

\end{longtable}
\end{document}


-
Harish's answer have helped me to achieve what I wanted. \numexpr is the answer I was looking for. Thank you guys! – jhad Mar 29 '14 at 14:53