I would like to use the X column type from the tabularx with the collcell package.
In the MWE below, I define:
\newcolumntype{R}{>{\collectcell\TitleColumn}{r}<{\endcollectcell}}% works \newcolumntype{T}{>{\collectcell\TitleColumn}{X}<{\endcollectcell}}% fails where the T applies the X column type (does not compile and thus is commented out in the MWE) and the R (for illustrative purposes) applies the r column type (which works).
The output has three tables:
Rcolumn type (to ensure syntax is correct)- Desired
Tcolumn type (commented out) - Desired Result of
Tcolumn type
The error message if table 2 (which uses the T columntype) is uncommented is:
Package array Error: Illegal pream-token (X): `c' used.
Notes:
- MWE is greatly simplified such that there is no need to actually use
collcellhere, but needed in actual use case where the\TitleColumnand\ColumnLmacros have more code.
Code:
\documentclass{article} \usepackage{collcell} \usepackage{tabularx} \usepackage{showframe} \newcommand{\ColumnL}[1]{#1} \newcommand{\TitleColumn}[1]{#1} \newcolumntype{R}{>{\collectcell\TitleColumn}{r}<{\endcollectcell}}% works \newcolumntype{T}{>{\collectcell\TitleColumn}{X}<{\endcollectcell}}% fails \newcommand*{\TabularContent}{% Label 1 Very Long& 62 & 79 \\ Label 2 Empty Row & \\ Label 3 Short& 732 & 31 \\ } \begin{document} \noindent 1. Column type \verb|R| (equivalent to centered \verb |r| column) works fine: \par\smallskip\noindent \begin{tabularx}{\linewidth}{@{}Rll@{}} \TabularContent \end{tabularx} \bigskip \noindent 2. Column type \verb|T| (equivalent to centered \verb |c| column) FAILS \par(commented out): \par\smallskip\noindent %\begin{tabularx}{\linewidth}{@{}Tll@{}}%% <--- How to get this to work % \TabularContent %\end{tabularx} \bigskip \noindent 3. Desired result of above \verb|T| column type is the \verb|X| column type:: \par\smallskip\noindent \begin{tabularx}{\linewidth}{@{}Xll@{}} \TabularContent \end{tabularx} \end{document} 