6

I have been reading Leslie Lamport's book on LaTeX and he discusses parboxes. He notes:

Many LaTeX users fail to realize how much they can do with the box-making commands described above. I will illustrate the power of these commands with a silly example...

Here is my own silly example. A few paragraphs with a single equation:

enter image description here

Is there any way to push the text in the \parbox paragraphs to the top? And why are the \parbox's drifting rightwards. I don't want to use \minipage quite yet because I haven't read the section too thoroughly. The \hrule might make things more complicated.

I certainly don't want to import too many new libraries, my goal is to understand the basic commands.

If you solve it with \minipage it's fine. I just don't know yet.


Here is the document:

\documentclass[12pt]{article}
%Gummi|065|=)

\usepackage[margin=0.5in]{geometry}

\title{Hello World}
\date{}
\begin{document}

\sffamily

\maketitle

\noindent 
\parbox[t]{0.5\textwidth}{
abcde abcde abcde abcde abcde abcde abcde abcde \\
abcde abcde abcde abcde abcde abcde abcde abcde \\
abcde abcde abcde abcde abcde abcde abcde abcde \\
abcde abcde abcde abcde abcde abcde abcde abcde 
\vfill
}
\parbox{0.5\textwidth}{
abcde abcde abcde abcde abcde abcde abcde abcde \\
abcde abcde abcde abcde abcde abcde abcde abcde \\
abcde abcde abcde abcde abcde abcde abcde abcde \\
abcde abcde abcde abcde abcde abcde abcde abcde 
$$ abc $$
abcde abcde abcde abcde abcde abcde abcde abcde \\
abcde abcde abcde abcde abcde abcde abcde abcde \\
abcde abcde abcde abcde abcde abcde abcde abcde \\
abcde abcde abcde abcde abcde abcde abcde abcde } 
\vspace{6pt}
\hrule
\vspace{6pt}
\parbox[t]{0.5\textwidth}{
abcde abcde abcde abcde abcde abcde abcde abcde \\
abcde abcde abcde abcde abcde abcde abcde abcde \\
abcde abcde abcde abcde abcde abcde abcde abcde \\
abcde abcde abcde abcde abcde abcde abcde abcde 
\vfill
}
\parbox{0.5\textwidth}{
abcde abcde abcde abcde abcde abcde abcde abcde \\
abcde abcde abcde abcde abcde abcde abcde abcde \\
abcde abcde abcde abcde abcde abcde abcde abcde \\
abcde abcde abcde abcde abcde abcde abcde abcde 
$$ abc $$
abcde abcde abcde abcde abcde abcde abcde abcde \\
abcde abcde abcde abcde abcde abcde abcde abcde \\
abcde abcde abcde abcde abcde abcde abcde abcde \\
abcde abcde abcde abcde abcde abcde abcde abcde }
\end{document}

Not unrelated:

1 Answers1

8

Some theory: every box has a reference point which is always placed on the baseline of the current line when the box is eventually typeset.

The reference point of \parbox[t] is the same as the first item inside it, in your case the first line; with no optional argument, the reference point is (about) midway between top and bottom of the box. This should explain why the top of the left box is about at the center of the right box.

The \vfill inside the left box does nothing, because the box is typeset at its natural vertical size, unless an additional optional argument is used to force a certain vertical size.

If you want both boxes to be aligned at their top, specify \parbox[t] for both.

The “drift” after \hrule is the normal indentation, which you're suppressing in the top pair of boxes with \noindent. Every \hrule command issues an implicit \par command.

You also get overfull boxes, because of the space (generated by the endline) after the left box.

In the fixed example below I removed the \\ in the top boxes. Note also that \vspace is better issued between paragraphs, so with a blank line above and below.

\documentclass[12pt]{article}

\usepackage[margin=0.5in]{geometry}

\title{Hello World}
\date{}
\begin{document}

\sffamily

\maketitle

\noindent 
\parbox[t]{0.5\textwidth}{
abcde abcde abcde abcde abcde abcde abcde abcde
abcde abcde abcde abcde abcde abcde abcde abcde
abcde abcde abcde abcde abcde abcde abcde abcde
abcde abcde abcde abcde abcde abcde abcde abcde 
\vfill
}% <--------- no space
\parbox[t]{0.5\textwidth}{
abcde abcde abcde abcde abcde abcde abcde abcde
abcde abcde abcde abcde abcde abcde abcde abcde
abcde abcde abcde abcde abcde abcde abcde abcde
abcde abcde abcde abcde abcde abcde abcde abcde 
\[ abc \]
abcde abcde abcde abcde abcde abcde abcde abcde
abcde abcde abcde abcde abcde abcde abcde abcde
abcde abcde abcde abcde abcde abcde abcde abcde
abcde abcde abcde abcde abcde abcde abcde abcde } 

\vspace{6pt}

\hrule

\vspace{6pt}

\noindent
\parbox[t]{0.5\textwidth}{
abcde abcde abcde abcde abcde abcde abcde abcde \\
abcde abcde abcde abcde abcde abcde abcde abcde \\
abcde abcde abcde abcde abcde abcde abcde abcde \\
abcde abcde abcde abcde abcde abcde abcde abcde 
}% <---- no space
\parbox[t]{0.5\textwidth}{
abcde abcde abcde abcde abcde abcde abcde abcde \\
abcde abcde abcde abcde abcde abcde abcde abcde \\
abcde abcde abcde abcde abcde abcde abcde abcde \\
abcde abcde abcde abcde abcde abcde abcde abcde 
\[ abc \]
abcde abcde abcde abcde abcde abcde abcde abcde \\
abcde abcde abcde abcde abcde abcde abcde abcde \\
abcde abcde abcde abcde abcde abcde abcde abcde \\
abcde abcde abcde abcde abcde abcde abcde abcde }

\end{document}

Beware that $$ should never be used in LaTeX, see Why is \[ ... \] preferable to $$ ... $$?

enter image description here

The reference point is at the left of the box; the vertical size from the reference point to the top of the box is the height, the size from the reference point to the bottom is the depth. The two boxes are aligned because they have the same height. It is the same reason why a and y are “aligned”: their reference points sit on the baseline; a has zero depth, y nonzero.

egreg
  • 1,121,712
  • 1
    I'm surprised you left the double dollar signs unchanged. – Torbjørn T. Mar 24 '18 at 16:20
  • @TorbjørnT. Oh, dear me! Let me fix it! – egreg Mar 24 '18 at 16:22
  • that's odd that putting \parbox[t] for the right paragraph, fixes the paragraph on the left. instead of learning all these rules, I eventually want to understand how LaTeX figures these things out – john mangual Mar 24 '18 at 16:34
  • @johnmangual There's no relationship between the two boxes, except that they have the reference point at the same distance from the top, which is the reason why they appear aligned. – egreg Mar 24 '18 at 16:43
  • @egreg what do you mean that alignment is just an illusion? – john mangual Mar 24 '18 at 16:47
  • @johnmangual Not at all! They are aligned because their reference points sit on the same baseline and the parts of the boxes above the reference point are equal in vertical size (TeXnically, they have the same height, but very different depth, that is, the vertical size below the baseline). – egreg Mar 24 '18 at 16:50