1

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:

tabu-collcell.pdf

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. – egreg Nov 20 '15 at 20:49
1

This turns out not to require much code. Override \collectcell to read everything up to \tabu@cellleft, then call the original \collectcell. Use \tabu@ifenvir to check whether the current environment is a tabu or longtabu.

\let\collectcell@notabu\collectcell
\def\collectcell@intabu#1#2\tabu@cellleft{#2\tabu@cellleft\collectcell@notabu{#1}}
\def\collectcell{\tabu@ifenvir\collectcell@intabu\collectcell@notabu}

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.