5

So I am trying to see if I can put two \vtop boxes side by side. The below is the closest I have gotten. This is a kind of a "plain-tex in latex" example.

\documentclass[fontsize=13pt,letterpaper,]{scrartcl}
\usepackage{geometry}
\usepackage{fontspec}
\setmainfont{Alegreya}[SmallCapsFont=Alegreya SC]

\setlength{\parindent}{0pt}

\long\def\Lcv#1#2{\hskip-1.3in \hbox to 2in{\hfil\itshape #1}%
    \hskip.5in\hbox to 3in{#2\hfil}}

\def\Lup#1#2{\Lcv{\vtop{#1}}{\vtop{#2}}}

\begin{document}

    \Lup{Hello this is your\\Crazy Uncle Harry}{Who joined the mob%
\\to feel good\\about himself}

     Hello and \\ Welcome to {\itshape my} World!!

\end{document}

enter image description here

As you can see from the code these are not really acting like \vtop boxes in the sense that in order to break paragraphs a \\ is needed.

I realize that there are various ways of accomplishing the same thing with various table environments and with \halign in plain tex. And that it is pretty simple to do so.

What I am looking for (if it exists at all) is a (hopefully simple) way of placing full \vtop boxes so that they are aligned along the baseline of a single line, "side by side". If it really cannot be done without incredible code wrangling, then I would appreciate that answer.---Thanks all.

  • 1
    try \hbox to 7cm {\vtop{\hsize=3cm Hello this is yourCrazy Uncle Harry} \vtop{\hsize=3.5cm Who joined the mob to feel good about himself}} – touhami May 6 '16 at 6:03
  • Oh, you put it into one big \hbox. I did not think of doing that. Nice! You could also do that \hbox to \hsize to get the full margin's width, right? – A Feldman May 6 '16 at 6:12
  • yes you're right. – touhami May 6 '16 at 6:45
  • yes if you are in hmode, but since using latex simplest is \parbox[t]{...}{...}\parbox[t]{...}{...} which naturally come side by side as latex box commands always start hmode before starting the box. – David Carlisle May 6 '16 at 7:07
7

What you need to know for doing a "box arithmetic" is

  • TeX changes vertical to horizontal mode at some places and returns back at others places.

  • \vbox or \vtop has its width given as most wider element in it. If this is whole paragraph then the width is \hsize. So it is typical to set a width of \vbox or \vtop by \vtop{\hsize= something ...}

When TeX is in vertical mode, then \vbox{...}\vbox{...} places boxes one above second. But when TeX is in horizontal mode then \vbox{...}\vbox{...} places boxes at the same line. For example:

\leavevmode \vtop{...}\vtop{...} % they are at one line 
                                 % in the paragraph started by \leavevmode 

\hbox{\vtop{...}\vtop{...}}      % they are at one line in the \hbox.

I wrote about TeX modes and boxes in detail in TeXbook naruby, sections 3.4 and 3.5.

IMHO, the "box arithmetic" principles and vertical/horizontal modes are basic knowledges of each TeX users. Unfortunately, LaTeX manuals hides them. LaTeX provides only a complicated construct like \begin{minipage}...\end{minipage}.

  • TeXbook naruby is not yet translated to English I would assume. I'd love to read it otherwise. – A Feldman May 6 '16 at 6:42
  • @AFeldman TeXbook naruby in not translated to English because my English is bad. – wipet May 6 '16 at 7:21
  • No so bad :) Your answer, for instance, is very understandable, and helpful. – A Feldman May 6 '16 at 14:38
2

You can use standard \parbox and \makebox commands.

There is a subtle point that you seem to be overlooking: the baselineskip might be not uniform with a \vtop (or \parbox[t], which is the same) approach.

\documentclass[fontsize=13pt,letterpaper]{scrartcl}
\usepackage[textwidth=5in,showframe]{geometry}
\usepackage{fontspec}
\setmainfont{Alegreya}[SmallCapsFont=Alegreya SC]

\setlength{\parindent}{0pt}

\newsavebox{\feldA}\newsavebox{\feldB}

\newcommand{\Lcv}[2]{%
  \par
  \hspace*{-1.3in}%
  \makebox[2in][r]{\itshape #1}%
  \hspace*{0.5in}%
  \makebox[3in][l]{#2}%
  \par
}

\newcommand{\Lup}[2]{%
  \sbox\feldA{\parbox[t]{2in}{\itshape#1\par\xdef\tpdA{\the\prevdepth}}}%
  \sbox\feldB{\parbox[t]{3in}{#2\par\xdef\tpdB{\the\prevdepth}}}%
  \ifdim\dp\feldA=\dp\feldB
    \ifdim\tpdA>\tpdB\let\tpdF\tpdA\else\let\tpdF\tpdB\fi
  \else
    \ifdim\dp\feldA>\dp\feldB
      \let\tpdF\tpdA
    \else
      \let\tpdF\tpdB
    \fi
  \fi
  \Lcv{\usebox{\feldA}}{\usebox{\feldB}}\par
  \prevdepth\tpdF
}

\begin{document}

\Lup{Hello this is your Crazy Uncle Unnamed ddd ddd ddd}
    {Who joined the mob to feel good about himself}

Hello and \\ Welcome to {\itshape my} World!!

\Lup{Hello this is your Crazy Uncle Harry yyy yyy yyy yyy}
    {Who joined the mob to feel good about himself}

Hello and \\ Welcome to {\itshape my} World!!

\end{document}

enter image description here

It's easy to see what goes wrong without the fuss with \prevdepth: just comment the line \prevdepth=\tpdF and you'll get

enter image description here

  • What a great answer! So if I understand (somewhat) your answer, the baseline skip to the next paragraph after the box is determined by the depth of the second box shipped out, both with a vtop and parbox. So, per your answer, you determine which of the 2 boxes has greater depth; then "swap" the depth reporter for box A, with the depth reporter for box B, if box A's depth is greater than that of box B? – A Feldman May 6 '16 at 14:34
  • @AFeldman Indeed: I store away the depth of the final lines in both boxes; then look which one has the greater “global depth”, because it's the one that will count for the correct spacing; after the \par, I reset the \prevdepth to the relevant value. – egreg May 6 '16 at 14:36
  • Your code is regular tex--latex. I wonder what this would look like in e-tex? And I bet that a lua version would be interesting too. – A Feldman May 6 '16 at 14:50
  • @AFeldman Not much different. But \parbox does many more thing than \vtop; using the primitive in LaTeX is best avoided. That's why I rejected your edit. If you are interested in a plain TeX answer, please ask a new question. – egreg May 6 '16 at 14:54
  • My bad. I should have known that if you wanted to present it that way, you would have. – A Feldman May 6 '16 at 15:00

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.