[metapost] aligning boxes

Alan Bram alan.bram at oracle.com
Sat Nov 15 02:32:19 CET 2008


How can I control the spacing and alignment of a series of boxes?

I would like all boxes to be the same width, with padding if
necessary.  Here's my attempt:

input boxes
\font\myfont=cmr10 scaled\magstep4\myfont


  boxjoin(ypart a.s = ypart b.n + .5u;
    xpart a.e=xpart b.e; xpart a.w=xpart b.w);

  boxit.a(btex medium length etex);
  boxit.b(btex short etex);
  boxit.c(btex a very long string indeed etex);



What seems to happen is that box "a" gets drawn at its natural width,
and then the other boxes match that width.  The result is that box "b"
has padding, and box "c" is too narrow: the long text spills out over
each side.

If I change the order, saying drawboxed(c,a,b), then I get the result
that I want.  But I of course don't want to have to adjust the
drawboxed command arguments each time the text content changes.

Is there anyway to do this?

Hmm, do I have to do something like write code to find the maximum,
then draw that one first, and then draw the others?  I thought the
"meta" way was to be able to declare linear equations in any order.

 - arb

More information about the metapost mailing list