10

Consider example1:

\setbox1=\vbox{
  \moveleft 1pt \vbox{\hrule width 4pt height 10pt depth 0pt}
  \hrule width 4pt height 10pt depth 0pt
}
\showbox1

The output:

\vbox(20.0+0.0)x4.0
.\vbox(10.0+0.0)x4.0, shifted -1.0
..\rule(10.0+0.0)x4.0
.\rule(10.0+0.0)x4.0

Consider example2:

\setbox2=\vbox{
  \moveright 1pt \vbox{\hrule width 4pt height 10pt depth 0pt}
  \hrule width 4pt height 10pt depth 0pt
}
\showbox2

The output:

\vbox(20.0+0.0)x5.0
.\vbox(10.0+0.0)x4.0, shifted 1.0
..\rule(10.0+0.0)x4.0
.\rule(10.0+0.0)x4.0

The outputs of example 1 and 2 differ with the width of the resulting vbox. With respect to \moveleft it is unchanged, whereas \moveright contributes to its width. What is the reason for this and where is it mentioned in TeXbook?

EDIT:

This is explained in TeXbook, page 81, third paragraph:

The width of a computed \vbox is the maximum distance by which an enclosed box extends to the right of the reference point, taking possible shifting into account. This width is always nonnegative.

The question now is: How to achieve the same behavior in example2, i.e., that the resulting document would be the same, but the width will be 4pt, instead of 5pt?

  • interesting although the difference isn't actually \moveleft v \moveright as moveright -1pt acts like \moveleft and \moveleft -1pt acts like \moveright including the width of the outer box. – David Carlisle Sep 2 '15 at 0:00
  • @DavidCarlisle: you are right, negative \moveright does not contribute to the width, and negative \moveleft does. Wait a second... I know the answer - page 81, third paragraph. – Igor Liferenko Sep 2 '15 at 0:09
  • Yes, you should self answer:-) – David Carlisle Sep 2 '15 at 0:23
  • No, I changed the question a bit - see EDIT. – Igor Liferenko Sep 2 '15 at 0:23
  • 1
    \moveright 1pt \rlap{\vbox.... – David Carlisle Sep 2 '15 at 0:25
6

The difference isn't actually \moveleft v \moveright as \moveright -1pt acts like \moveleft 1pt and \moveleft -1pt acts like \moveright 1pt including the width of the outer box.

As noted in the updated question the TeXBook documents this as

The width of a computed \vbox is the maximum distance by which an enclosed box extends to the right of the reference point, taking possible shifting into account. This width is always nonnegative.

Possibly the easiest way to add a box ensuring that it does not affect th width of the outer box, even if shifting left or right is to use \rlap to hide the box width, so \rlap{\vbox{\moveright ... or just use a kern rather than a shifted box, so \rlap{\kern-1pt\vbox{...

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.