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}
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.

| improve this answer | |
  • \protected\def\leavevmode{\ifvmode\expandafter\indent\fi} ;) – Joseph Wright Jan 2 at 22:35
  • @JosephWright i know, but the question didn't ask what \ifvmode\expandafter\indent\fi does:-) – David Carlisle Jan 2 at 22:37
  • Yes, that question (why so wide) is better. I'll try to edit the post. – Sigur Jan 2 at 22:45
  • @Sigur it is essentially unrelated to \leavevmode you see the same with \vbox{\hbox{a}} which is the width of an a and \vbox{a} which is the width of the page. – David Carlisle Jan 2 at 22:52
  • 1
    @Sigur it starts a paragraph in just the same way that a does, it's just less visible than an a – David Carlisle Jan 2 at 23:09

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.