I am trying to understand the sizes of boxes and skips so I decided I wanted to typeset text directly on top of some other text. I don't want to use textpos or anything like that. I am trying to figure out how big of a skip I need to get back to where I was. I would like the green, red and blue boxes to perfectly overlap.

2 Answers
2

There are many factors involved here. The main one is the interline glue; Knuth uses the term ‘glue’ to denote the vertical spacings inserted manually or automatically when stacking boxes that are part of paragraphs.

The distance between the bottom of the first line to the bottom of the second line will be equal to \baselineskip (12pt is the default value if ten point size is in force). In this case TeX will insert between the two lines a vertical glue equal to the difference between \baselineskip and the height of \boxB.

the glue inserted would be the difference between \baselineskip and the sum of the height of ‘planet’ and the depth (of the previous line). There would be a corrective factor if this difference is less than a threshold (contained in the parameter \lineskiplimit).

because these boxes don't trigger the insertion of the corrective factor.

The case of \sbox{\boxA}{\parbox{\textwidth}{Hello\par World}} is quite different, because TeX treats a \parbox as a unique object whose height is computed in an apparently bizarre way: take the "apparent total height" (that is, how high the box would be if it were sitting on the baseline of the last line inside it) and divide it by two; let's say that x is the length so obtained, while d is the depth of the last line in the \parbox; the height of the box will be x + 2.5pt, the depth x – 2.5pt + d. Thus

\usebox{\boxA}\par\usebox{\boxA}

does trigger the insertion of the corrective factor: the two boxes are stacked one above the other, and TeX inserts \lineskip glue (default 1pt) between them. So, in order to back up exactly you have to sum up the depth of \boxA, its height and \lineskip:

(it's easier to access directly at the dimensions of the boxes with the low level commands \ht and \dp).

Why that bizarre computation? The answer requires knowing about \vcenter, but it's not really important. Once one knows the height and depth of the involved boxes it's easy to predict the final outcome under normal circumstances.

Where does the 2.5pt comes from? It's not a universal value: this is for Computer Modern fonts at 10pt size. The actual value is the distance from the baseline of the fraction line when one typesets $\frac{1}{2}$. The \vcenter primitive centers a box vertically with respect to this math axis. The height of the math axis is a parameter in the current math symbol font.