TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to enclose a text in a box. My problem is that when the code below is placed at the beginning of a line it causes a line-break/carriage-return (the box stays on a line by itself, the rest of paragraph starts at the next line). But it is OK when I use it in the middle or the end of a line. What is causing this behavior?

\kern#1 \hrule}%
\def\emptybox#1#2#3{\hbox spread #3{\hfil
\vtop spread #2{
\vbox spread #1{\vfil}
share|improve this question
\hbox doesn't start horizontal mode; add \leavevmode as the first token in the replacement text. – egreg Oct 15 '12 at 19:15
up vote 8 down vote accepted

Contrary to what can be thought at first, \hbox doesn't start horizontal mode. The reason is that a \vbox can be made up by stacking \hboxes:


and this would result in


and the width of the resulting \vbox would be that of the widest \hbox.

The same is true about \vbox, \vtop, \box and \copy. Conversely, \unhbox and \unhcopy applied to a box register containing an \hbox will start horizontal mode. If you intend to use those commands as starting paragraphs, add \leavevmode:

      \kern#1 \hrule
  \hbox spread #3{\hfil
    \vtop spread #2{
      \vbox spread #1{\vfil}

A more efficient macro for creating an empty box with specified height, depth and width is

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.