[Tex/LaTex] Is it possible to create a \newcolumntype-like macro accepting more than one arguments where one of them is an optional argument

macrostables

Is it possible to create a \newcolumntype-like macro accepting more than one argument and one of them is an optional argument?


I want to create a column type A that can accept more than 1 argument such that I can create a tabular as follows:

\begin{tabular}{|A[2cm]{1cm}{5cm}|c|l|r|}
...
\end{tabular}

Note: the column type A accepts 3 arguments in this example.

Best Answer

Herbert has explained how to do mandatory arguments. Optional arguments is doable but requires some low-level hackery, auxiliary functions and is not for the faint-hearted. You can see two versions of the same approach in numprint and siunitx (the later is an adaptation of the former).

\makeatletter
\newtoks\mytoks
\mytoks\expandafter{\the\NC@list}
\newcolumntype{A}{}
\NC@list\expandafter{\the\mytoks \NC@do A}
\renewcommand*{\NC@rewrite@A}[3][]{%
  \@temptokena\expandafter{%
    \the\@temptokena 
      % INSERT DEFINITION HERE!
  }%
  \NC@find
}
\makeatother