TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:


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

share|improve this question
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
up vote 11 down vote accepted

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).

\NC@list\expandafter{\the\mytoks \NC@do A}
share|improve this answer
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:



foo & bar & baz & foobar

share|improve this answer
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

Your Answer


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.