5

Using pdftex.

Given two sample programs

test0.tex

\vbox{
\hbox{X}
\hbox{Y}
}

\bye

test1.tex

\vbox{
\hbox{X}
\hrule
\hbox{Y}
}

\bye

gives the following outputs.

test0.png

test0.png

test1.png

test1.png

So, adding a \hrule between the two \hboxes actually decreases their vertical distance.

Why is this and what parameters influence the vertical distance between two sibling hboxes?

1
  • 2
    if you want to retain the vertical spacing, it's usually sufficient to add a \strut to the end of the first and the beginning of the second line. there are other places that a \strut can be beneficial, for example a line with no descenders at the end of a multi-line table cell.) Commented Jul 9, 2014 at 12:32

3 Answers 3

5

Quoting from the TeXbook, page 79 (last single dangerous bend)

Exception: No interline glue is inserted before or after a rule box. You can also inhibit interline glue by saying \nointerlineskip between boxes.

In the case without the rule, the interline glue is added as usual: compute the sum s of the depth of the upper line and the height of the lower line; if the difference bs (where b is the natural length of \baselineskip) is greater than \lineskiplimit, insert glue of length bs (with the plus and minus components of \baselineskip); otherwise, insert \lineskip glue.

1
  • Great, exactly what I was looking for! (Or, not so great: the rule sounds complicated. I'll have to read up on glue again).
    – Jo So
    Commented Jul 9, 2014 at 11:02
2

Actually this is not a property that is unique to \hbox. The happens due the default spacing defined above and below the \hrule construct. You can change the spacing manually by using the \kern command.

\vbox{
\hbox{X}
\hrule
\kern2pt %change the pts according to your needs
\hbox{Y}
}

Alternatively, you could also define a macro for this.

1

Maybe you need this:

\newdimen\savedprevdepth

\vbox{
\hbox{X}
\savedprevdepth=\prevdepth \hrule \prevdepth=\savedprevdepth
\hbox{Y}
}

\bye

Explanation: \prevdepth primitive register is set to the depth of the last box in the vertical list. It is set to magic value -1000pt when the vertical list is empty or when the \hrule is inserted to the vertical list. The \baselineskip/\lineskiplimit/\lineskip processing for the next box is active only if \prevdepth isn't equal to -1000pt.

2
  • "Maybe" and the shortness of the answer qualify this rather as a comment. Did you check it or can provide an output?
    – user31729
    Commented Jul 9, 2014 at 11:42
  • 1
    @ChristianHupfer OK, I added more information. I hoped that this info is simply available for interested persons.
    – wipet
    Commented Jul 9, 2014 at 12:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .