1

In a tabu environment (tabu 2.8 package), I use \multicolumn to omit some cells' preamble (and occasionally span multiple columns). Unfortunately this breaks down the width calculations when there are non-X columns: if the \multicolumn{1}{l}{TEXT} is wider than the widest normal cell, the table as a whole becomes wider.

The manual mentions this as a known problem that can be fixed by including \tabuphantomline, but I'm not seeing any effect.

MNWE:

\documentclass{article}
\usepackage{tabu}
\usepackage{tabularx}
\pagestyle{empty}
\setlength{\parindent}{0pt}
\setlength{\parskip}{1em}
\begin{document}
This document illustrates difficulties with the \texttt{tabu} environment. All
tables are supposed to be \verb`\textwidth` wide, just like the present
paragraph.

\verb`tabularx` for reference: \\
\begin{tabularx}{\textwidth}{>{\ttfamily}lX}
  \hline
  foo & wibble \\
  \multicolumn{1}{l}{foo} & wibble \\
  \hline
\end{tabularx}

\verb`tabu` with a \verb`\multicolumn`: \\
\begin{tabu}{>{\ttfamily}lX}
  \hline
  foo & wibble \\
  \multicolumn{1}{l}{multicolumn} & wibble \\
  \hline
\end{tabu}

\verb`tabu` with a \verb`\multicolumn` and a \verb`\tabuphantomline`: \\
\begin{tabu}{>{\ttfamily}lX}
  \hline
  \tabuphantomline
  foo & wibble \\
  \tabuphantomline
  \multicolumn{1}{l}{multicolumn} & wibble \\
  \tabuphantomline
  \hline
\end{tabu}

\end{document}

tabu-multicolumn-mwe.png

How can I make \multicolumn work as desired (influencing the width of the column(s) that it replaces, but not the width of the table as a whole, as illustrated above with tabularx?)

1

This problem only seems to arise when you're using a \multicolumn command and passing 1 to it as its first argument and using a non-X column type. Compare the following:

\documentclass{article}
\usepackage{tabu}
\usepackage{parskip}

\begin{document}

This document illustrates difficulties with the \texttt{tabu} environment.
All tables are supposed to be \verb`\textwidth` wide, just like the present paragraph.

\verb`tabu` with a \verb`\multicolumn` and a \verb`\tabuphantomline`:

\begin{tabu}{>{\ttfamily}lX}
  \hline
  foo & wibble \\
  \multicolumn{1}{c}{multicolumn} & wibble \\
  \hline
  \tabuphantomline
\end{tabu}

\begin{tabu}{>{\ttfamily}llX}
  \hline
  foo & wibble & wobble \\
  \multicolumn{2}{c}{multicolumn} & wibble \\
  \hline
  \tabuphantomline
\end{tabu}

\end{document}

which produces:

enter image description here

So this appears to be a bug with how \tabuphantomline handles \multicolumns with a width of 1 when there are non-X column types.

If you're just using \multicolumn with a width of 1 to change the horizontal alignment of a single cell, you could instead define a new macro called \CenteredCell, for example, and thereby avoid having to use \multicolumn{1}... and \tabuphantomline:

\documentclass{article}
\usepackage{tabu}
\usepackage{parskip}

\newcommand*{\CenteredCell}[1]{%
  \begin{tabular}{@{}>{\rmfamily}c@{}}
    #1%
  \end{tabular}}

\begin{document}

This document illustrates difficulties with the \texttt{tabu} environment.
All tables are supposed to be \verb`\textwidth` wide, just like the present paragraph.

\verb`tabu` with a \verb`\multicolumn` and a \verb`\tabuphantomline`:

\begin{tabu}{>{\ttfamily}lX}
  \hline
  foo & wibble \\
  \multicolumn{1}{c}{multicolumn} & wibble \\
  \hline
  \tabuphantomline
\end{tabu}

\begin{tabu}{>{\ttfamily}lX}
  \hline
  foo & wibble \\
  \CenteredCell{multicolumn} & wibble \\
  \hline
\end{tabu}

\end{document}

This produces:

enter image description here

2
  • Thanks, but that solution is completely specific to the toy example in the question. In the real world, I have more complex preambles that do more than alignment, some do all kinds of crazy things like index the content of the column. I really need that \omit. Jan 19 '16 at 19:42
  • @Gilles Fair enough. Figuring out what the bug is currently beyond me, I think, but perhaps this answer will prompt someone with more knowledge and time to look into it. Sorry this doesn't help for your use case.
    – Adam Liter
    Jan 19 '16 at 19:50

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.