4

Problem

I have a tabu table where the text in one column is larger than the text in the rest of the table. To avoid the text to come to close to the top rule I insert a strut (where the bottom has been smashed) in the relevant cell (as suggested here).

However, it seems that the \smash[b]{\strut} causes unintended extra vertical space to be inserted unless inserted inside the \textbf{}.

If I use an ordinary \strut (including the decending 0.3\baselineskip) or if I create the smashed strut manually using a \rule{0pt}{0.7\baselineskip} (which should have the same dimensions} it seems to work fine no matter where I place it.

Can somebody explain why it matters whether the \smash[b]{\strut} is inserted inside or outside a \textbf{} block?

Example

Here is a simple example demonstrating the behaviour. First the result and then the LaTeX source.

Result

Various attempts to fix vertical space in tabu environment

LaTeX source

\documentclass[a4paper]{article}
\usepackage[top=3cm, bottom=3cm, width=6cm]{geometry}
\usepackage[parfill]{parskip}

\usepackage{tabu}
\usepackage{amsmath}

\begin{document}
  Large text in \verb$tabu$ environment is too close to the uppermost line:

  \begin{tabu}{|c|}
    \hline
    \begin{tabu} {lX[c]r}
      left & {\LARGE\textbf{MIDDLE}} & right
    \end{tabu} \\
    \hline
  \end{tabu}

  To fix it we insert a smashed strut \emph{outside} the \verb$\textbf$ block but it does not look nice:

  \begin{tabu}{|c|}
    \hline
    \begin{tabu} {lX[c]r}
      left & {\LARGE\smash[b]{\strut}\textbf{MIDDLE}} & right
    \end{tabu} \\
    \hline
  \end{tabu}

  Putting the smashed strut \emph{inside} \verb$\textbf$ apparently works:

  \begin{tabu}{|c|}
    \hline
    \begin{tabu} {lX[c]r}
      left & {\LARGE\textbf{\smash[b]{\strut}MIDDLE}} & right
    \end{tabu} \\
    \hline
  \end{tabu}

  If the strut is not smashed it works \emph{outside} \verb$\textbf$:

  \begin{tabu}{|c|}
    \hline
    \begin{tabu} {lX[c]r}
      left & {\LARGE\strut\textbf{MIDDLE}} & right
    \end{tabu} \\
    \hline
  \end{tabu}

  If the smashed strut is replaced by a \verb$\rule$ is also works:

  \begin{tabu}{|c|}
    \hline
    \begin{tabu} {lX[c]r}
      left & {\LARGE\textbf{\rule{0pt}{0.7\baselineskip}MIDDLE}} & right
    \end{tabu} \\
    \hline
  \end{tabu}

\end{document}
2

There is a fundamental difference between an X and a c column. The latter is typeset as if it were \makebox[<dimen>]{<text>} (the <dimen> is automatically computed, while the former is \parbox{<dimen>}{<text>} (the text will be centered because of the c option to X).

While a \smash gives no problem in a horizontal box (\makebox), it doesn't start a paragraph in a \parbox. Use \leavevmode before \smash in case of doubts.

As you noticed \rule works. A different workaround than using \smash[b] might indeed be

\rule{0pt}{\ht\strutbox}

which might be a bit mysterious for the uninitiated.

The \strut works when inside \textbf because this macro starts a paragraph.

The input I'd prefer would be

\begin{tabu}{|c|}
\hline
\begin{tabu} {lX[c]r}
left & {\LARGE\leavevmode\smash[b]{\strut}\bfseries MIDDLE} & right
\end{tabu} \\
\hline
\end{tabu}

In case you need this in several places, you could define a new command.

\usepackage{xparse}
\NewDocumentCommand{\tabustrut}{o}
 {%
  \leavevmode\IfNoValueTF{#1}{\smash{\strut}}{\smash[#1]{\strut}}%
 }

so you could use \tabustrut for \leavevmode\smash{\strut} and \tabustrut[b] for \leavevmode\smash[b]{\strut}. There's no problem in using \leavevmode in a c column, it will do nothing.

enter image description here

  • Excellent explanation! So AFAIK \leavemode means exit vertical mode and go to horizontal mode. Without \leavemode (in the X column which is a parbox) the smashed strut is stacked (in vertical mode) on top of the text. Is that correctly understoood? – mgd Oct 19 '14 at 8:12
  • @mgd That's exactly what happens. – egreg Oct 19 '14 at 9:15

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.