8

Using \smash after a tabular seems too screw up vertical spacing. Wheras after a paragraph vertical spacing is fine. Witness for yourself:

\noindent
\begin{tabular}[t]{@{}ll}%
  One\cr
  Two\cr
\end{tabular}

\smash{Three}

TeX output

\noindent
One\\
Two

\smash{Three}

TeX output

Why is that so? What is TeX doing in each case?

  • Interestingly, the \smash bypasses the \par logic. In both cases, there is no \par indent. Put a \strut before either \smash and the indent comes back. Strange. – Steven B. Segletes Sep 27 '13 at 0:14
  • @StevenB.Segletes True, and there is no \parskip either. – Ernest A Sep 27 '13 at 0:30
  • 2
    @StevenB.Segletes \smash workings end with \box0 after a series of assignments which never change the mode (of course, restricted horizontal mode is entered when setting \box0, but this is irrelevant). So if \smash is issued in vertical mode, it doesn't cause TeX to switch to horizontal mode. The only box related commands that force horizontal mode are \unhbox and \unhcopy. – egreg Sep 27 '13 at 8:51
10

First of all, never use \cr in tabular, but always \\.

Now to the problem.

  1. A tabular, by default is as high as deep. Height is the vertical amount by which a box sticks above the baseline, depth the same, but below the baseline.

  2. \noindent\begin{tabular}...\end{tabular}<blank line> makes a one line paragraph, that is packaged in a box put on the main vertical list.

  3. \smash doesn't start a paragraph and, indeed, you don't get an indent because the box is placed directly in the vertical list.

  4. Between boxes, TeX puts interline glue so that baselines are \baselineskip apart, unless this would make boxes overlap, based on the depth of the top box and the height of the bottom box. If

    \baselineskip-<depth of top box>-<height of bottom box> < \lineskiplimit
    

    TeX inserts \lineskip glue instead.

  5. The bottom box has zero height, because it was smashed.

  6. The computation makes TeX think that no overlap happens

Result: overlap.

This is more evident if you add two rows to the tabular and "show" the boxes. To understand the effect, you need to remember that a tabular extends below the baseline of the last row, because each row has a \strut.

\documentclass{article}
\fboxrule=0.1pt % hair rule
\fboxsep=-\fboxrule % don't add to the box dimensions
\newcommand{\showbaseline}{\makebox[0pt][l]{\leaders\hrule\hskip3cm}}

\begin{document}
\noindent\showbaseline
\fbox{\begin{tabular}{@{}l}
One\\
Two
\end{tabular}}

\smash{\showbaseline\fbox{Three}}

\noindent\showbaseline
\fbox{\begin{tabular}{@{}l}
One\\
Two\\
Three\\
Four
\end{tabular}}

\smash{\showbaseline\fbox{Five}}
\end{document}

In the first example you see that the baselines are exactly 12pt apart, while in the second the bottom of the tabular is 1pt from the second baseline because TeX, in this case, inserted the \lineskip glue.

enter image description here

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.