# \hbox in “p”-column (tabular) destroys row layout

The following example code shows a problem with my \vertgap command, which is just intended to add some space above and below the mandatory argument after encapsulating it in an \hbox (for tall contents). It works fine in l-type columns, but obviously not in p-type columns. On my first tries I didn't recognize that, because it works in longtable (note: the example code lacks head- and footlines), not ignoring the auto-inserted \centering, too.

My goal can be seen in the longtable: all three table rows have equal height. Is it possible to achieve this behavior in tabular, too?

Addendum: simple use of \hbox in a p-type column is enough to show up the problem.

\documentclass{article}
\usepackage{longtable}
\usepackage{array}

\newcommand{\vertgap}[1]{\hbox{\vbox{\kern0.25ex\vtop{\hbox{#1}\kern0.25ex}}}}%
%\newcommand{\vertgap}[1]{\hbox{\vbox{\hrule height0.25ex\vtop{\hbox{#1}\hrule height0.25ex}}}}%
% The commented-out command above shows the inserted gaps - these seem to be ok.

\begin{document}

\begin{tabular}{|l|>{\centering}p{2in}|l|}
\hline%
aaaa: & 4711-0815 & any\\
\hline%
aaa: & \vertgap{0815} & any\\
\hline%
aa: & 4711 & any\\
\hline%
\end{tabular}

\begin{longtable}{|l|>{\centering}p{2in}|l|}
\hline%
aaaa: & 4711-0815 & any\\
\hline%
aaa: & \vertgap{0815} & any\\
\hline%
aa: & 4711 & any\\
\hline%
\end{longtable}

\end{document}


\hbox is a TeX primitive and shouldn't be used in LaTeX unless you know how it works in detail (you can run in trouble with stuff like colors or placement --- as you did). The corresponding LaTeX command to use is \mbox and that fixes your problem.

The main reason is that an \hbox doesn't start a paragraph if encountered in vertical mode, it is simply added left aligned. Therefore \centering has no effect. \mbox ensures that the box becomes part of the paragraph.

### Update

Maybe I should add that the same is true for \kern, \vbox, \vtop, i.e., they aren't supported LaTeX "document-level" commands. All of them are of course commands one needs to build packages etc, but on user-level they should preferably be avoided.

Having said that, there isn't actually a LaTeX equivalent for \vtop{\kern...\hbox{#1}\kern...} as this produces a vertical box which is as wide as the hbox inside. LaTeX only offers vertical boxes that have a defined width, e.g., \parbox and the moment you start a paragraph inside the defined width is going to be the width of the box regardless of the content. Well, one could use \shortstack{..\\[..] ...} I guess but that would be kind of a hack too. So the coding the way it is is probably the simplest way to achieve the desired results (as long as one knows about the side effects of these commands).

• Thank you very much to correct my "boxed confusion" this fast...! – tueftl Apr 5 '13 at 11:30
• By the way: is there a recommendable documentation that differentiates between user-level and TeX core commands, maybe in german, too? – tueftl Apr 8 '13 at 11:06
• @tueftl the official documentation for core LaTeX is the LaTeX manual by Leslie Lamport and for the more extended stuff the LaTeX Companion 2ed (or LaTeX-Begleiter in German). Both of them differenciate between LaTeX and TeX commands mainly by not discussing the TeX commands, i.e., they are not manuals for building complex packages in which you need to go low-level with internal LaTeX and direct TeX commands. Best resource for TeX is on one hand the TeXbook or the these days freely available TeX by Topic. There is nothing directly for LaTeX internals other the the kernel docu source2e – Frank Mittelbach Apr 8 '13 at 15:11