[texhax] Centering within an arbitrary vbox

Hartmut Henkel hartmut_henkel at gmx.de
Mon May 25 23:38:45 CEST 2009


On Mon, 25 May 2009, Aditya Mahajan wrote:

> On Mon, 25 May 2009, Philip G. Ratcliffe wrote:
>
> >> I have this bit of TeX code:
> >>
> >>    \line{\hfill\vbox{\hbox{Chapter}\hbox{8}}}
> >>
> >> Which renders something like this (pardon my ASCII art):
> >>
> >>
> >> |                                     Chapter|
> >> |                                     8           |
> >>
> >> What I want is for the "8" to be centered under the "Chapter"
> >> but with the combined vbox flush right.
> >>
> >> [snip]
> >
> > The tabular environment is probably th simplest solution:
> >
> > \line{\hfill\vbox{%
> >  \tabcolsep=0pt % to keep things flush
> >  \begin{tabular}{c}
> >    Chapter\\8
> >  \end{tabular}
> > }}
>
> Or, if you are using plain TeX, use \halign
>
> \line{\hfill\vbox
>    {\halign{\hfill#\hfill \cr
>     Chapter \cr
>     8 \cr}}}

but here the right adjustment is not exact, as there are spurious
spaces, after the "Chapter" and after the "8". An easy cure is to write
always, invariably "#\unskip" instead of "#". Or you need to type e. g.
"Chapter\cr", but the "#\unskip" in the preamble seems to be more
practical, more fail-safe, gives more freedom to align the source text.

Regards, Hartmut


More information about the texhax mailing list