I have a document with tables where I automatically create cross-references based on the contents of some cells. For this, I use the collcell
package to pass the cell contents to a macro.
I'm currently using tabular
(with array
) and tabularx
, but I'd like to move some of these tables to tabu
. Unfortunately, tabu
and \collectcell
don't play well together. MNWE (I replaced the linkification automation by a simple use of \meaning
to show what's going on):
\documentclass{standalone}
\usepackage{collcell}
\usepackage{tabu}
\usepackage{tabularx}
\def\showmeaning#1->#2.{#2}
\newcommand{\linkify}[1]{\def\linkifycontent{#1}\expandafter\showmeaning\meaning\linkifycontent.}
\newcolumntype{t}{>{\ttfamily}l}
\newcolumntype{T}{>{\collectcell{\linkify}}t<{\endcollectcell}}
\newcolumntype{U}{>{\ttfamily\collectcell{\linkify}}l<{\endcollectcell}}
\begin{document}
\begin{tabularx}{6em}{TU}
foo & bar \\
\end{tabularx}
\qquad
\begin{tabu}{TU}
foo & bar \\
\end{tabu}
\end{document}
Output:
With tabular
or tabularx
, \collectcell
captures the content of the cell. But with tabu
, it also captures tokens inserted before the cell content, including \tabu@cellleft
which is automatically inserted by tabu
.
What can I replace \collectcell
with in my column definitions so that only the cell content is captured?
I want to keep column definitions that work both in tabu and non-tabu environments, because I use both. I can't just make the decision based on the environment names, because I define some wrappers around tabularx
and I use other environments from the tabu
package (longtabu
is one of my reasons for moving to tabu
).
Ideally I'd like to keep being able to nest column type definitions (as I do now with T
using t
, and \ttfamily
not ending up in the collected cell content), but if it's really needed I can arrange to always put collectcell
at the innermost level around the built-in column types (l
, X
, p
, …).
tabu
doesn't play well with many other packages, I'm afraid.