4

This is centered:

$$\vbox{\halign{#\cr A\cr}}$$

Why this is not centered?

$$\halign{#\cr A\cr}$$

BTW, why \hbox{\halign{#\cr A\cr}} does not work?

1

1 Answer 1

7

\halign is a vertical command, meaning that it starts vertical mode when encountered, as this example shows

\parindent=0pt % To see the left margin
Foo bar baz \halign{#\cr A\cr} bar foo baz
\bye

enter image description here

Vertical commands raise an error when used in restricted horizontal mode (i.e. within \hbox).

However, there exists the display alignment, specified as

$$⟨assignments⟩ \halign⟨box specification⟩{...} ⟨assignments⟩$$

where the ⟨assignments⟩ are optional things like parameter changes that do not produce any math lists. Such an alignment is shifted by \displayindent and surrounded by \abovedisplayskip and \belowdisplayskip glue. (From TeX by Topic, Sec 25.2.1.) Usually within a paragraph \displayindent is 0pt (but \parshape or \hangindent can change this); that's why you see a left-aligned formula

\parindent=0pt % To see the left margin
Foo bar baz
$$\halign{#\cr A\cr}$$
Foo bar baz
$$\displayindent=1em\halign{#\cr A\cr}$$
\bye

enter image description here

4
  • Answer to exercise 22.14 in TeXbook uses $$\vbox{\halign.... But answers to 22.9, 22.7 and 22.6 consistently use $$\halign.... Just wondering... Jan 14, 2020 at 8:39
  • @IgorLiferenko Can't look at it right now. Hopefully later...
    – campa
    Jan 14, 2020 at 8:42
  • @IgorLiferenko the first one is a normal alignment in a vbox, that is then centred by $$, the second form is the special display alignment construct as described in this answer. Jan 14, 2020 at 9:26
  • @IgorLiferenko 22.9 has \halign to\displaywidth, the other two have \halign to\hsize.
    – egreg
    Jan 14, 2020 at 17:14

You must log in to answer this question.

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