2

Based on this question and the amazing @egreg's answer, I decided to make some tests to study and learn some boxes behavior. More precisely, to understand the \leavevmode.

In the first example, one horizontal box with two vertical ones inside it with some horizontal boxes there, and everything is fine.

In the second example, I put \leavevmode in the first vertical box and as I expected the behavior was changed to horizontal, so aaa and bbb are side-by-side.

But the output is completely affected by that. That is, the second vertical box is out or margin.

Thus, why the second example is too wide?

enter image description here

MWE

\documentclass[11pt,a4paper]{report}
\usepackage{showframe}
\newcommand{\linha}{\noindent\makebox[0pt][l]{\rule[0pt]{\linewidth}{.4pt}}}

\begin{document}%
\noindent%
\hbox{%
  \vbox{%\leavevmode%
    \hbox{aaa}%
    \hbox{bbb}%
  }%
  \vtop{%
    \hbox{xxx}
    \hbox{yyy}
    \hbox{zzz}
  }%
  123456
}%

\medskip

\noindent%
\hbox{%
  \vbox{\leavevmode%
    \hbox{aaa}%
    \hbox{bbb}%
  }%
  \vtop{%
    \hbox{xxx}
    \hbox{yyy}
    \hbox{zzz}
  }%
  123456
}
\end{document}
David Carlisle
  • 757,742
Sigur
  • 37,330

1 Answers1

2

It is defined by

\newbox\voidb@x % permanently void box register
\def\leavevmode{\unhbox\voidb@x}

so in horizontal mode it does essentially nothing, and in vertical modes it forces the start of horizontal mode (so like the luatex primitive \quitvmode other than some edge effects on the timing of when \everypar tokens get triggered.

\hbox stack in vertical direction in vmode, and in horizontal direction in hmode (hence the names of the modes) which accounts for the different output that you show.

Perhaps you are asking about why

 \vbox{\leavevmode%
    \hbox{aaa}%
    \hbox{bbb}%
  }%

is so wide? Having started a paragraph inside the vbox, at the end of the box the paragraph is broken in to lines of length \hsize which is \textwidth here, so this box is the full width of the page.

Sigur
  • 37,330
David Carlisle
  • 757,742