2

I am trying to use a macro to define the alignment of a table as shown below:

\documentclass{article}
\begin{document}
\def\align{|l|c|}
\begin{tabular}{\align}
1 & 2 \\
\end{tabular}
\end{document}

However when I do this I get a message message that seems to indicate that \align is not a valid alignment and 'c' is used instead. It must have to do with the timing of the expansion. How do I get this to work right?

5
  • The actual error message is: ! Package array Error: Illegal pream-token (\align): `c' used. Aug 20, 2015 at 15:00
  • Do you really need array package? In basic LaTeX there are no errors during compilation. Aug 20, 2015 at 15:12
  • 1
    This will raise an error only if the array package is loaded. In that case you can do \newcolumntype{\foo}{|l|c|} (not \align, because this will conflict with amsmath, once you load it).
    – egreg
    Aug 20, 2015 at 15:15
  • I actually using this with longtable and in a macro, but I tried to come up with a simple example that had the same problem. Aug 20, 2015 at 15:40
  • @egreg in the actual latex code I am building I do not use align as the defined value. Aug 20, 2015 at 15:41

1 Answer 1

3

The posted example is completely misleading and runs without error.

If the array package is used, then macros in the alignment are not expanded, and \newcolumntype can be used for abbreviated column alignment constructs.

\documentclass{article}
\usepackage{array}
\begin{document}
\newcolumntype{a}{|l|c|}
\begin{tabular}{a}
1 & 2 \\
\end{tabular}
\end{document}
1
  • Yes. This was my mistake. I used a class (not article) which automatically included array. Thanks for the clarification on this. Aug 21, 2015 at 19:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .