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

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.

-
Perhaps a bit more detail on what is wanted might be useful! I'm not sure if it is the macro \newcolumntype itself or the resulting letter that you want to alter. –  Joseph Wright Dec 30 '10 at 18:51
@Joseph, please see my new edit. –  xport Dec 30 '10 at 19:00

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

-
Thanks. I works. –  xport Dec 30 '10 at 19:44
Is there a reason for using \csname NC@rewrite@A\endcsname (and the \expandafters) rather than \NC@rewrite@A? –  clemens Jan 26 '13 at 21:28
@cgnieder Not here, but there is where I've copied it from! I'll edit. –  Joseph Wright Jan 26 '13 at 21:59

not with an optional argument, only with mandatory ones:

\documentclass{article}
\usepackage{array}

\newcolumntype{A}[3]{@{\vrule\kern#1\vrule}p{#2}@{\vrule\kern#3\vrule}}
\begin{document}

\begin{tabular}{|A{2cm}{1cm}{5cm}|c|l|r|}
foo & bar & baz & foobar
\end{tabular}

\end{document}

-
first of all thanks. However, if I define an optional argument as follow \newcolumntype{A}[3][1cm] and \begin{tabular}{|A[2cm]{1cm}{5cm}|c|l|r|}, I got compilation errors. –  xport Dec 30 '10 at 19:12
I wrote "not" with an optional argument! –  Herbert Dec 30 '10 at 19:18
ok. I have not read before. Thanks. –  xport Dec 30 '10 at 19:22