8

This is a bit of a long post, so apologies in advance. I would like to nest xymatrices in Xy-pic so that entire xymatrices would be treated as single entries in another xymatrix.

I tried the obvious method of putting an xymatrix as an entry in another, which didn't work.

I then did some search and read a few manuals, and found one method which only deals with two matrices side by side, with the starting point of the arrows not at the centers of the two matrices, as in the code below:

\[ \xymatrix{ & R_1 \ar[r] \ar[d] & P \\ R_2 \ar[r] \ar[d] & B & \\ Q && } \qquad\rightarrow\qquad \xymatrix{a} \] 

I then found on a thread on the Xy official site someone asking the same question as me; and he was told to use xygraph, and that there is an xymovie about this type of construction.

I couldn't find the movie; and couldn't find much information on how to use xygraph either ( the section in Xy-pic RM didn't include many examples).

Eventually I tried this:

\xy \xygraph{!M \xymatrix{ & R_1 \ar[r] \ar[d] & P \\ R_2 \ar[r] \ar[d] & B & \\ Q && } ([u]X : ?, [l]Y : ?) } \endxy 

which still didn't do what I wanted.

So is there a way to nest xymatrices? Or maybe I need to use some other graphics packages? Thank you very much for you help! (And your time for reading this.)

7
  • 3
    Your question "Or maybe I need to use some other graphics packages?" is dangerous! It'll be interesting to see how long you have to wait before getting an answer starting "This is really easy using TikZ ...". Commented Aug 30, 2010 at 7:34
  • @Andrew: I’m tempted. Commented Aug 30, 2010 at 9:22
  • Actually it is not possible to nest TikZ matrices. Commented Aug 30, 2010 at 9:47
  • @Caramdir: I'm surprised at that, but there's 19minutes between your comments so I guess you tried quite a few possibilities. However, I suspect that "nesting matrices" is a means to an end and if user1025 could clarify that end, it might be easier to help. I'll leave a comment to that end ... Commented Aug 30, 2010 at 10:33
  • 1
    @user1025: could you explain what you want to achieve by nesting xy-matrices? In particular, do you want the ability to nest to arbitrary depth, or just one Big Matrix for positioning and then Sub Matrices for the actual information? Presumably you're wanting to draw arrows between the sub-matrices, is that the main functionality you want? Commented Aug 30, 2010 at 10:36

2 Answers 2

3

You could use several xy matrices inside an xy environment and refer to them. Here's an example, using pieces of your code, which prints two xy matrices and connects them by an arrow:

\documentclass{article} \usepackage[matrix,arrow]{xy} \begin{document} \[ \xy \xymatrix"m"{ & R_1 \ar[r] \ar[d] & P \\ R_2 \ar[r] \ar[d] & B & \\ Q && } \POS+(42,0) \xymatrix{ \ar@{<-}["m"rr] A \ar[r] & B } \endxy \] \end{document} 

The first matrix is named "m". The command \ar@{<-}["m"rr]in the second matrix draws an arrow from the current point to the node P of the matrix "m" using the relative positioning rr from the upper left corner. I used @{<-} to revert the arrow.

Output:

alt text

This way you could use several matrices and connect them by arrows. Regarding actual nesting: the xy-pic reference manual says:

Matrix nesting is not safe.

2
  • Thanks. How did you find the 42 in \POS+(42,0), was it try and error or is it possible to work out from the matrix "m"? Also I would really like to have the starting and end points of arrows the centers of matrices they connect if that's possible. Commented Aug 30, 2010 at 22:06
  • I've just tested the value and 42 looked well. It should be possible to connect the centers, perhaps look at the reference manual: ctan.tug.org/tex-archive/macros/generic/diagrams/xypic/xy/doc/… Commented Sep 1, 2010 at 16:51
1

Your second example wouldn't compile because you shouldn't add the \xymatrix command after M. The documentation states that

M<matrix> will be insert the result of \xymatrix<matrix> as the node

So

\xy \xygraph{!M{ & R_1 \ar[r] \ar[d] & P \\ R_2 \ar[r] \ar[d] & B & \\ Q && } ([u]X : ?, [l]Y : ?) } \endxy 

will compile. On the other hand, reading the manual, it states that for an \xymatrix

the entire matrix is an object itself with reference point its top left entry

arrows going to and from it won't center correctly. Which can be seen if you compile the above code.

2
  • Thanks, but I would really like a way to center arrows. Commented Aug 30, 2010 at 22:01
  • I noticed. But I can't find a way to do it semi-automatically with Xy-pic. You can always position/draw arrows by hand (or through references as Stefan describes), but I suspect you don't want that. I'll edit if I think of something. Commented Aug 30, 2010 at 22:05

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.