Discussion:
[Xy-pic] Vertical alignment in xymatrix
Michael Abbott
2003-03-03 21:55:21 UTC
Permalink
I've got a couple of problems with controlling vertical alignment with
xymatrix, and I'd like to know if there are any solutions.


Firstly, I'd like the option (in fact, I'd rather it were the default) for
the entries in each cell to be aligned on the equation centre line rather
than being vertically centred.

Consider the example:
\xymatrix{-^X \ar[r] & -_X}
Ideally the two - signs and the arrow should all be on a common
centre-line, but they're not (the difference is subtle but significant and
annoying, and gets worse the bigger the sub- and superscripts get).

Can I do anything about this?


Secondly, I'd also like the option to control where the baseline of the
entire \xymatrix{} expression is, so that I can write, for example:

A'--> B'
| |
Blah blah A --> B and so on

and have the *bottom* line of the matrix alined up with the body of the
text. At present I can line up with the *top* line, or put \vcentre{}
around the whole thing, but I can't figure a way to align the matrix on
any other baseline.
(For reference, a genuinely practical application is putting the
trailing punctuation after a diagram in the right place. Ideally it
should be aligned on the *bottom* line.)


These two alignment issues have been bugging me for ages, so I'll be glad
of any advice!

Many thanks,
Michael Abbott
Lengyel, Florian
2003-03-03 22:57:49 UTC
Permalink
One way to handle the default vertical alignment in xypic is perhaps
ludicrous--after a certain point one wants to get things to work, even if
the additional effort to read the manual is \epsilon, in protest against
having to decipher the manual further to resolve an issue that must have
been patently obvious to the developers, and which therefore deserves
special mention in neon lights in the manual, one resorts to the \phantom
command, as follows:

Instead of this:
\xymatrix{-^X \ar[r] & -_X}

you do this:
\xymatrix{-^X_{\phantom{X}} \ar[r] & -_X^{\phantom{X}}}

FL

-----Original Message-----
From: Michael Abbott [mailto:***@araneidae.co.uk]
Sent: Monday, March 03, 2003 9:24 AM
To: XyPic mailing list
Subject: [Xy-pic] Vertical alignment in xymatrix


I've got a couple of problems with controlling vertical alignment with
xymatrix, and I'd like to know if there are any solutions.


Firstly, I'd like the option (in fact, I'd rather it were the default) for
the entries in each cell to be aligned on the equation centre line rather
than being vertically centred.

Consider the example:
\xymatrix{-^X \ar[r] & -_X}
Ideally the two - signs and the arrow should all be on a common
centre-line, but they're not (the difference is subtle but significant and
annoying, and gets worse the bigger the sub- and superscripts get).

Can I do anything about this?

One way to handle the default vertical alignment in xypic is perhaps
ludicrous--after a certain point one wants to get things to work, even if
the additional effort to read the manual is \epsilon, in protest against
having to decipher the manual further to resolve an issue that must have
been patently obvious to the developers, and which therefore deserves
special mention in neon lights in the manual, one resorts to the \phantom
command, as follows:

Instead of this:
\xymatrix{-^X \ar[r] & -_X}

you do this:
\xymatrix{-^X_{\phantom{X}} \ar[r] & -_X^{\phantom{X}}}

FL

P.S. Actually, I'd like to know the real answer myself.
Michael Abbott
2003-03-04 00:03:06 UTC
Permalink
Post by Michael Abbott
\xymatrix{-^X \ar[r] & -_X}
\xymatrix{-^X_{\phantom{X}} \ar[r] & -_X^{\phantom{X}}}
Heh. Eww.

I'm hoping that the developers have a cleaner solution :)
Michael Abbott
2003-03-06 01:11:06 UTC
Permalink
Post by Michael Abbott
I've got a couple of problems with controlling vertical alignment with
xymatrix, and I'd like to know if there are any solutions.
Does the silence on this question mean that the people who can answer this
question are away or busy, or does it mean that there is no solution?

(Forgive me Florian, but your answers, although amusing, don't count as
solutions!)
Vadim Yu. Radionov
2003-03-06 01:48:40 UTC
Permalink
Hi, Michael and others!

Consider these lines for solutions to mentioned problems.

Entrymodifiers is a weird thing --- i faild to apply a modifier to
a single cell later. But it aligns the arrow in the axis (actually,
shifts the entries).

@!R0 at the beginning of \xymatrix guarantees the fixed \xymatrixrowsep
distance between entries' centers, thus you can move it up by
the same amount.

Actually, i made no tests of the latter, just guessed.

As for punctuation, i use to put it in \rlap{} in the last cell.

\documentclass[12pt]{book}
\usepackage[matrix,arrow]{xy}
\entrymodifiers={+!!<0pt,\fontdimen22\textfont2>}
\xymatrixrowsep={3pc}
\xymatrixcolsep={3pc}

\begin{document}
This is a test \raisebox{3pc}{$\xymatrix@!R0{& C \\ A_1^1 \ar[r]\ar[ur] &
B \ar[u]}$}.
\end{document}

Yours, Vadim
Lengyel, Florian
2003-03-06 03:36:34 UTC
Permalink
Hi, Michael and others!

Consider these lines for solutions to mentioned problems.

Entrymodifiers is a weird thing --- i faild to apply a modifier to
a single cell later. But it aligns the arrow in the axis (actually,
shifts the entries).

@!R0 at the beginning of \xymatrix guarantees the fixed \xymatrixrowsep
distance between entries' centers, thus you can move it up by
the same amount.

Actually, i made no tests of the latter, just guessed.

As for punctuation, i use to put it in \rlap{} in the last cell.

\documentclass[12pt]{book}
\usepackage[matrix,arrow]{xy}
\entrymodifiers={+!!<0pt,\fontdimen22\textfont2>}
\xymatrixrowsep={3pc}
\xymatrixcolsep={3pc}

\begin{document}
This is a test \raisebox{3pc}{$\xymatrix@!R0{& C \\ A_1^1 \ar[r]\ar[ur] &
B \ar[u]}$}.
\end{document}

Yours, Vadim

I can offer no better thanks for this than to use it in a project I'm
working on; for example:

\documentclass[12pt]{book}
\usepackage[all]{xy}
\usepackage{amsfonts}
% etc
\entrymodifiers={+!!<0pt,\fontdimen22\textfont2>}
\xymatrixrowsep={3pc}
\xymatrixcolsep={3pc}

\begin{document}

Examples of finite free categories are the discrete categories
$n=\{0,\ldots,n-1\}$ and the ordered categories
$\mathbf{n}=\{\xymatrix{0\ar[r]&1\ar[r]&\cdots\ar[r]&n-1}\}$ for
$n\ge 0$, as well as the subcategories
\[
\underline{\Lambda}=%
\left(\raisebox{1.9pc}{\xymatrix@!R0{& (0,0)\ar[dl]\ar[dr] & \\ %
(1,0) & & (0,1) %
}}\right),\ \ {\underline{\Lambda}}^{\mathrm{op}}=%
\left(\raisebox{1.9pc}{ \xymatrix@!R0{(1,0)\ar[dr] & & (0,1)\ar[dl]\\
& (1,1)}}\right)
\]
of $\mathbf{2}\times\mathbf{2}$, which is itself not free.

\end{document}

FL
Ross Moore
2003-03-06 05:52:07 UTC
Permalink
Hello Michael, and other Xy-pic users,
Post by Michael Abbott
Post by Michael Abbott
I've got a couple of problems with controlling vertical alignment with
xymatrix, and I'd like to know if there are any solutions.
Does the silence on this question mean that the people who can answer this
question are away or busy, or does it mean that there is no solution?
Silence from whom ?
Your question has generated some discussion, which indicates the
right kind of approach to adopt.
Post by Michael Abbott
(Forgive me Florian, but your answers, although amusing, don't count as
solutions!)
Adjusting \entrymodifiers is often the right thing to do, to get
improved alignment when some cell entries have descenders (e.g. subscripts)
but others do not.

In your case, however, because of the unusual shape created by
$-_X$ and $-^X$ where the sup/subscripts are larger than the main atom
itself, then it is necessary to adjust some of the cells' actual
contents rather than the way the cells are positioned.

This is actually what \xymatrix @1 and \xymatrix @2 attempt to do
--- but they may not be able to cope as well as you would like.

So set the \everyentry directly:
$$
\everyentry{\vphantom{{-}_X^X}}
\xymatrix....{.... }
$$

Now the invisible strut constructed by the \vphantom will be
placed into *every* cell of your matrix-like diagram, as part
of the <object> being built within that cell.
When the strut is larger than the visible contents, then it will
be determining the vertical size of the cell.
For two adjacent cells, each with height determined in this way,
the TeX base-lines should appear to line-up.

The draw-back is that arrows pointing to the cell may terminate at
a greater distance than you might prefer, upon meeting the boundary
of a larger rectangle.

If that is really a problem, then you will have to adjust the contents
of cells individually, rather than collectively. Of course this
makes it difficult to read the mathematics in your LaTeX source, as
cells will then become a mixture of content and positioning constructions
(like the first reply, using \vphantom within the sup/subscripts).


Try using \everyentry first, to see if that gives you adequate satisfaction.


Regards

Ross Moore
Post by Michael Abbott
_______________________________________________
Xy-pic mailing list
http://tug.org/mailman/listinfo/xy-pic
Michael Abbott
2003-03-06 06:38:13 UTC
Permalink
Post by Ross Moore
Silence from whom ?
Sorry, I think I got too impatient!
Post by Ross Moore
Post by Ross Moore
Adjusting \entrymodifiers is often the right thing to do, to get
improved alignment when some cell entries have descenders (e.g. subscripts)
but others do not.
I'll try and understand what the \entrymodifiers solution is doing...

I'm slightly confused by this discussion though. Perhaps I'm
misunderstanding something.

As I understand it, each entry is generated with a particular shape, where
the shape defines the centre and horizontal and vertical extends from the
centre. I'm presuming that the entry is then placed in the matrix with
its centre at the selected point in the matrix, and that lines will point
towards this selected point.

Now the problem is how this centre relates to the mbox (the typeset
mathematical expression) being placed. I can't find the reference, but I
seem to recall that every bit of mathematical text has, as well as the
normal baseline with height and depth, a mathematical centre-line -- which
is, I think, at a defined vertical offset above the baseline. As I recall
it, the - sign is *on* the centre-line.

So what I don't understand is this: how does xymatrix determine the
"centre" of an mbox being placed in the matrix? Is the centre literally
half way between top and bottom? What I'm hoping to achive is some way in
which the centre can be *on* the mathematical centre-line, in other words,
at the standard offset from the baseline.

If this could be done then nothing special would need to be done to ensure
that adjacent entries of differing shapes line up properly.
Post by Ross Moore
In your case, however, because of the unusual shape ...
Of course, special hacks to deal with unusual shapes are what I want to
avoid, as otherwise I'm going to be constantly having to tweak each array
whenever I introduce a new entry of a different shape :(
Post by Ross Moore
The draw-back is that arrows pointing to the cell may terminate at
a greater distance than you might prefer, upon meeting the boundary
of a larger rectangle.
Indeed, another reason I don't want to do that.
Post by Ross Moore
If that is really a problem, then you will have to adjust the contents
of cells individually, rather than collectively. Of course this
makes it difficult to read the mathematics in your LaTeX source, as
cells will then become a mixture of content and positioning constructions
(like the first reply, using \vphantom within the sup/subscripts).
Indeed, indeed. Not at all desireable.


Am I misunderstanding something? It seems to me that in principle the
notion of positioning the centre on the *centre-line* is straightforward
and would solve all my problems...
Michael Abbott
2003-03-06 15:08:25 UTC
Permalink
Post by Michael Abbott
Post by Ross Moore
Silence from whom ?
Sorry, I think I got too impatient!
That's understandable. Dismissing my ludicrous suggestions as non-solutions
isn't! ;)
I think the issue is this:

All the solutions so far seem to involve hacking the math text so that its
height and depth match up so that the resulting text is symmetrical around
the centre-line.

Is this analysis correct?

In particular, is it really the case that xy just throws away the baseline
of the text when converting it into a box? That's really what I'm trying
to get at, and why I was so dismissive about your answers (I do apologise;
I didn't mean to be rude).

If this really is the case, and this is actually a deficiency in xy, how
difficult will it be to create an option which computes the xy box with
the centre in the *right* place?
Alexander Perlis
2003-03-06 20:24:53 UTC
Permalink
Post by Michael Abbott
I'll try and understand what the \entrymodifiers solution is
doing...
Vadim's elegant solution (a few posts ago) is probably what you want.
He also posted it back in 2001. I studied this alignment problem half
a year ago and wrote up my tribulations in an article for TUGboat and
arrived at essentially the same solution. A preprint is available at:

http://grad.math.arizona.edu/~aprl/280802
Post by Michael Abbott
Now the problem is how this centre relates to the mbox (the typeset
mathematical expression) being placed. I can't find the reference,
but I seem to recall that every bit of mathematical text has, as
well as the normal baseline with height and depth, a mathematical
centre-line -- which is, I think, at a defined vertical offset
above the baseline. As I recall it, the - sign is *on* the
centre-line.
That special line is the "axis". That's what \vcenter uses, and
vertical delimiters (such as parenthesis) have equal height and depth
when measured from the axis.
Post by Michael Abbott
So what I don't understand is this: how does xymatrix determine the
"centre" of an mbox being placed in the matrix? Is the centre
literally half way between top and bottom?
Each entry has a bounding box, and the Xy-pic reference point
defaults to the center of that box.
Post by Michael Abbott
What I'm hoping to achive is some way in
which the centre can be *on* the mathematical centre-line, in other
words, at the standard offset from the baseline.
Actually, that's already the case. Xy-pic aligns dropped objects so
that the reference point (which defaults to the center) lands on the
axis.

Take a look at my article (see above for URL), which discusses this
matter and includes illustrations.

Vadim's solution (also illustrated in my article) is to move the
Xy-pic reference point away from the center of the bounding box, in
such a way that when that reference point gets placed on the axis,
the usual TeX reference point (lower-left-corner of letters) lands on
the usual baseline.
Post by Michael Abbott
[...] using \vphantom [...]
I am not a fan of the \vphantom technique (used by the @1
construction) to affect alignment. It does so, but also affects the
bounding box, which subsequently affects arrows between objects.
Post by Michael Abbott
All the solutions so far seem to involve hacking the math text so
that its height and depth match up so that the resulting text is
symmetrical around the centre-line.
The solution Vadim and I use is *not* of this nature.
Post by Michael Abbott
In particular, is it really the case that xy just throws away the
baseline of the text when converting it into a box?
That's true, but you still have access to the distance between the
baseline and the center while the box is being formed. That distance
is \fontdimen22\textfont2. (If you change \objectstyle to, say,
\scriptstyle, then you'll want \fontdimen22\scriptfont2.)
Post by Michael Abbott
If this really is the case, and this is actually a deficiency in
xy, how difficult will it be to create an option which computes
the xy box with the centre in the *right* place?
I agree that Xy-pic ought to support an option to automatically move
the reference point using \fontdimen22. In fact, at the end of my
article (see above for URL) I make suggestions concerning the syntax
of such an option. If any reader knows the Xy-pic source code well
enough to implement these ideas, please do so! (I'm hardly
qualified.) And of course I would welcome a discussion of my
suggestions. More users will benefit ultimately if the matter is
given careful thought through a community discussion prior to
implementation.

Alex


__________________________________________________
Do you Yahoo!?
Yahoo! Tax Center - forms, calculators, tips, more
http://taxes.yahoo.com/
Ross Moore
2003-03-06 20:24:54 UTC
Permalink
Post by Michael Abbott
All the solutions so far seem to involve hacking the math text so that its
height and depth match up so that the resulting text is symmetrical around
the centre-line.
Is this analysis correct?
Yes.

If you were to use a graphics program, such as Adobe Illustrator,
then this is possibly exactly what you would do, using its alignment
templates.
The alternative would require you to be very careful with rulers,
and probably would not end up looking as good.
Post by Michael Abbott
In particular, is it really the case that xy just throws away the baseline
of the text when converting it into a box? That's really what I'm trying
Sort of.
At least this is what happens using \xymatrix ...
Post by Michael Abbott
to get at, and why I was so dismissive about your answers (I do apologise;
I didn't mean to be rude).
The problem is that \xymatrix uses TeX's \halign based on the \ialign primitive.
This is what is used by most aligned environments in LaTeX, whether math
or otherwise.
You cannot align the top rows of a {tabular} environment unless the top line
has the same height in adjacent cells.
In this case you are actually aligning via the top of the cell, not aligning
via the baseline.
Post by Michael Abbott
If this really is the case, and this is actually a deficiency in xy, how
There are many diagrams for which \xymatrix is not the best environment to use.

The reason \xymatrix is so popular, and usually the first choice for
things that look like commutative diagrams, is that it has a familiar syntax.
Thus it's easy to learn to use quickly, even though it is limited in its
capabilities. Nevertheless, it gives better commutative diagrams than
other packages, in most cases --- excluding Barr's diagram package,
which is based upon Xy-pic. :-)

One alternative is to use \xygraph .

This lets you control the placement of elements much more accurately.
But you may have to work a little bit harder to master the syntax,
and you may need to plan ahead to a greater extent than with \xymatrix .

In particular, you will have to explicitly name <object>s that are to be
used as targets of arrows, since there is no assumption that everything
lies within a regular grid of cells.
Post by Michael Abbott
difficult will it be to create an option which computes the xy box with
the centre in the *right* place?
Within the context of \xymatrix yes, that is actually rather hard.

Using \xygraph, or explicit Xy-pic kernel commands, this can indeed be
done --- at the expense of a more complicated syntax.
It also will depend on the specific definition of "right place"
that you wish to adopt.


I hope this helps you to better understand the nature of the problem.


Regards

Ross Moore
Post by Michael Abbott
_______________________________________________
Xy-pic mailing list
http://tug.org/mailman/listinfo/xy-pic
Michael Abbott
2003-03-09 20:56:23 UTC
Permalink
Post by Ross Moore
There are many diagrams for which \xymatrix is not the best environment to use.
One alternative is to use \xygraph .
Ah, ok. Thank you for the pointer. Time to take another look at it, I
guess!
Post by Ross Moore
This lets you control the placement of elements much more accurately.
But you may have to work a little bit harder to master the syntax,
Yes. The last time I looked at xygraph I bounced off it, as the syntax
seems to be a *lot* harder to understand, and xymatrix works nicely.
Post by Ross Moore
[How] difficult will it be to create an option which computes the xy
box with the centre in the *right* place?
Within the context of \xymatrix yes, that is actually rather hard.
Using \xygraph, or explicit Xy-pic kernel commands, this can indeed be
done --- at the expense of a more complicated syntax.
It also will depend on the specific definition of "right place"
that you wish to adopt.
Umm. Could I beg a quick helping hand then to get me started?

I started with the (artificial) example
\xymatrix{-^X \ar[r] & -_X}
where I want the two - signs to be aligned on the *same* horzontal line
without having to perform ugly hacks on the heights and depths of the two
expressions.

How could this be written using \xygraph, please?
Alexander Perlis
2003-03-07 04:34:58 UTC
Permalink
Post by Ross Moore
There are many diagrams for which \xymatrix is not the best
environment to use.
The reason \xymatrix is so popular, and usually the first choice
for things that look like commutative diagrams, is that it has a
familiar syntax.
Another reason \xymatrix is so popular is that the Xy-pic User's
Guide is devoted to it. I suspect many users read enough of the Guide
to get their work done, and never "graduate" to reading the Reference
Manual or the many nice papers that Ross Moore and Kris Rose have
written (in TUGboat and elsewhere). In short, my guess is that many
users of Xy-pic don't even know that there is such a thing as
\xygraph or an underlying kernel language. In other words, to many
users, Xy-pic and \xygraph are one and the same.

I myself was turned onto \xygraph by the Kris Rose article on
conceptual alignment:

http://www.diku.dk/forskning/topps/bibliography/1994.html
http://evarose.net:800/~krisrose/ECCT-94/rose/

Once turned on, I studied the Xy-pic Reference Manual to learn more.
When converting old documents in which diagrams were hacked together
using matrix environments, I usually save time by using \xymatrix.
But for all new diagrams, I use \xygraph. It does everything
\xymatrix does, but also so much more, and gives so much freedom in
how to describe a diagram.

To those readers who haven't used it much, I heartily recommend
checking it out. The key difference between \xymatrix and \xygraph is
"global versus local". With \xygraph, instead of working on a grid
moving from top left to bottom right one row at a time, you instead
give the position of each object relative to some other object. Thus
you can start in the middle of the diagram, or the lower-right,
whatever seems most natural. This is what Kris Rose means when he
says that \xygraph is "conceptual": you specify the pieces of the
diagram in the same order you would write them on a board when
explaining the diagram to a colleague. It's marvelous!

Alex


__________________________________________________
Do you Yahoo!?
Yahoo! Tax Center - forms, calculators, tips, more
http://taxes.yahoo.com/
Ross Moore
2003-03-10 15:45:46 UTC
Permalink
Hello Michael,
Post by Michael Abbott
Umm. Could I beg a quick helping hand then to get me started?
I started with the (artificial) example
\xymatrix{-^X \ar[r] & -_X}
where I want the two - signs to be aligned on the *same* horzontal line
without having to perform ugly hacks on the heights and depths of the two
expressions.
How could this be written using \xygraph, please?
Try having a look at this:

http://www-texdev.ics.mq.edu.au/ABBOTT/xygtest.pdf

Ross Moore
Post by Michael Abbott
_______________________________________________
Xy-pic mailing list
http://tug.org/mailman/listinfo/xy-pic
Loading...