2

I'm having a hard time lining up elements in different boxes, and I have reduced the issue (I think) to a minimal example.

The code below puts two fboxes next to each other. They have the same internal elements, but in a different vertical order.

One has

\hbox to \pwidth{\hfill\fbox{\vbox to \baselineskip{\phantom{0000}}}}
\hbox to \pwidth{\hfill XXXX}

The other has

\hbox to \pwidth{\hfill XXXX}
\hbox to \pwidth{\hfill\fbox{\vbox to \baselineskip{\phantom{0000}}}}

My question is "Why do these boxes not have the same total height?"

The height of each box should be 2*\baselineskip plus whatever extra space is allotted for the drawing of the frames.

Full code and output below:

\documentclass[10pt]{letter}
\usepackage[top=0.5in, bottom=0.5in, left=0.5in, right=0.5in]{geometry}

\begin{document}
\newlength{\pwidth}
\setlength{\pwidth}{52pt}
\lineskip=0pt
\Large
\hbox{
\hbox to \pwidth{
\fbox{
\parbox{\pwidth}{
\hbox to \pwidth{\hfill\fbox{\vbox to \baselineskip{\phantom{0000}}}}
\hbox to \pwidth{\hfill XXXX}
}}}
\hskip 10pt
\hbox to \pwidth{
\fbox{
\parbox{\pwidth}{
\hbox to \pwidth{\hfill XXXX}
\hbox to \pwidth{\hfill\fbox{\vbox to \baselineskip{\phantom{0000}}}}
}}}
}

\end{document}

Here is the output:

Output

Here is the output if I put an additional "XXXX" row in each box. Now the box on the right is taller. But in both cases you should have one XXXX row that gets extra overhead glue (from \baselineskip) and one that does not (the top one). This suggests that there is also something going on in addition to the issue pointed out by Gustavo in his comment:

3-line version

If I put an additional XXXX row below both, the two have the same height:

4-line version

  • 2
    Because, in the first box, the XXXX box has \baselineskip glue above it (since it is not very tall), whereas, in the second one, the framed box has \lineskip glue above itself (since its height is already equal to the \baselineskip value). – GuM Aug 12 '16 at 22:17
  • Thanks, Gustavo. One thing I noticed is that if I add an additional "XXXX" line to each, the box on the right becomes taller than the box on the left. That seems strange because at that point there should be one "XXXX" row in each that gets cheated of overhead space (the top XXXX in each box). – David R Aug 12 '16 at 22:54
  • Added 3-line and 4-line versions. – David R Aug 12 '16 at 23:00
  • You need to think about where the baseline is at each point and separate the depth below from the height above in your head, if you see what I mean. You can't lump it altogether as if all the vertical spacing is for the same kind of thing. TeX is using different bits of it for different reasons (top this up or keep this steady and drop that below etc.). At least, that's how I understand @GustavoMezzetti 's explanation. – cfr Aug 13 '16 at 0:57
5

Please forgive me if I say that it seems you are not completely understanding how interline glue works: I’ll try to give a simple explanation that avoids TeXnicalities.

Interline glue is a device by means of which TeX tries to maintain a fixed distance between the baselines of the text. With your settings (including \Large) this distance equals 18 pt. Now, there are three possibilities:

  1. Framed box followed by “XXXX” box. In this case, a box of depth 3.4 pt (that is, reaching 3.4 pt below the baseline) is followed by a box of height (above the baseline) equal to 9.84 pt; then, \baselineskip glue for 4.76 pt is inserted in between. Indeed, 3.4 + 4.76 + 9.84 = 18.0.

  2. “XXXX” box followed by framed box. Since the height of the framed box is 21.4 pt (18.0 + 3.4 from \fboxsep) and therefore exceeds by itself the desired distance, \lineskip glue (currently 1.0 pt) is inserted between the two boxes.

  3. Two “XXXX” boxes in a row, both with height equal to 9.84 pt and depth equal to 0 pt. In this case, a thicker \baselineskip glue of 8.16 pt is necessary: indeed, 0 + 8.16 + 9.84 = 18.0.

So, in your three-line version we have:

  • in the left-hand box, XXXX + \lineskip + framed + thinner \baselineskip + XXXX;

  • in the right-hand box, XXXX + thicker \baselineskip + XXXX + \lineskip + framed.

Hence we see that the right-hand box is taller.

I’ll leave the analysis of the four-line case to you.

  • Thanks so much, Gustavo. I think the point that was confusing me is that the framed box has a depth of 3.4 pt. I just assumed that everything other than descenders would start on the baseline [i.e., have a depth of 0.] I would very much appreciate it if you could tell me how you determined that the height of XXXX was exactly 9.84pt and that the depth of the framed work was 3.4 pt. How can I find this type of information for myself in the future? – David R Aug 14 '16 at 3:14
  • Oh, I see.. because fboxsep = 3.4 pt. – David R Aug 14 '16 at 5:10
  • @DavidR: I determined the height of the XXXX box and the depth of the framed one by means of \showlists (of course… :-) By the same means I also checked the other values indicated in my answer. Do you know what \showlists is? – GuM Aug 15 '16 at 20:40
  • Nope, but I'll know to look it up in the future. Thanks! – David R Aug 16 '16 at 22:15

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.