I'm trying to use a conditional in the column setup for my tabular
. That is, the definition of one column (actually several columns) is dependent on a boolean value (as set up from the etoolbox
package).
I need the array
package too, but once I add it in (or other packages that rely on it), I get an error:
! Package array Error: Illegal pream-token (\ifbool): `c' used.
I've tried packing my column definition into a new column type as described here, as well as some csname
tricks described here, to no avail.
Here's a minimal (non-)working example
\documentclass{article}
\usepackage{etoolbox}
\usepackage{array}
\newbool{MyBoolean} \setbool{MyBoolean}{true}
\begin{document}
\begin{tabular}{
l
\ifbool{MyBoolean}{c}{}
r
}
Left & \ifbool{MyBoolean}{Center &}{} Right \\
Left & \ifbool{MyBoolean}{Center &}{} Right
\end{tabular}
\end{document}
Any ideas?
Best Answer
I would use
collcell
to collect and conditionally set the column entry:The correction for a false boolean is to remove any column separation (of width
\tabcolsep
) using a negative space.