# \shortstack in \newcolumntype

I want to have a column type where to every cell a certain text is added.

I was thinking of using:

\newcolumntype{C}{>{\shortstack\bgroup extratext\\}c<{\egroup}}


I expected this would would give me the desired result but it complains about missing } and {. An explanation why this happens would be greatly appreciated.

MWE:

\documentclass{article}
\usepackage{array}
\newcolumntype{C}{>{\shortstack\bgroup extratext\\}c<{\egroup}}
\begin{document}
\begin{tabular}{CCC}
a & b & c
\end{tabular}
\end{document}

• \shortstack doesn't allow its argument to be between \bgroup and \egroup (only a few macros do, because they're based on primitives, but this behavior is very particular). – egreg Nov 21 '17 at 17:06

You can't specify the argument to \shortstack by enclosing it between \bgroup and \egroup. In some cases this works or seems to, but just by chance.

With collcell you can do it: if you declare \usepackage{collcell}, the syntax is

>{\collectcell\macro}c<{\endcollectcell}


Complete example:

\documentclass{article}
\usepackage{array,collcell}

\newcolumntype{C}{>{\collectcell\extratext}c<{\endcollectcell}}
\newcommand{\extratext}[1]{\shortstack{extratext\\#1}}

\begin{document}

\begin{tabular}{CCC}
a & b & c
\end{tabular}

\end{document}