With the array package we can define a new column specifier that can be used in a tabular environment (e.g. \newcolumntype{A}[{>{\centering \arraybackslash}m{2cm}}).

It is even allowed to define a new column type with an argument like \newcolumntype{B}[1]{>{\centering \arraybackslash}m{#1}}.

Now I need to let the new colomn type argument have a default value like \newcolumntype{C}[1][2cm]{>{\centering \arraybackslash}m{#1}} but this results in a compilation error.

So I am asking if it is possible to provide a default argument to the \newcolumntype command?


\newcolumntype{A}[1]{>{\centering \arraybackslash}m{#1}}

%\newcolumntype{B}[1]{3cm]{>{\centering \arraybackslash}m{#1}}

  column width = 2 cm & column width= 4cm \\\hline
    hello world hello world hello world &  hello world hello world hello world\\\hline

enter image description here


You can not do that without somewhat extensive changes to the array package, adding the declaration possibility would be simple but the mechanism used to replace defined columntypes does not have anything that would help detect optional parameters, so you would have to change that mechanism, and doing that without breaking packages that depend on it (colortbl, tabularx, tabulary, ....) might be tricky.

If you accept an empty argument rather than an optional one it is easy, so the benefits of such a change compared to the risk of breaking existing code are rather discouraging adding such a feature.

\newcolumntype{A}[1]{>{\centering \arraybackslash}m{\if!#1!3cm\else#1\fi}}

would allow A{} to use a default width of 3cm

  • Thank's for you reply! Unfortunately for me I have intensively used the column type A with no argument. – Hafid Boukhoulda Jan 9 at 12:57
  • 2
    @HafidBoukhoulda ok in that case, I think the answer is to use A for the default case and B for the case with an argument. It's what I'd do. – David Carlisle Jan 9 at 15:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.