# commutative diagram having drawings as objects

I need to draw a commutative diagram having drawings as objects, like in this link which is also shown below. I have some problems:

1. xy-pic "slants" the objects;
2. "matrix" library in TiKZ is not happy to have other TiKZ commands in the matrices I wnat to draw.

What can I do? This is a tentative answer to my problem:

$\xymatrix@C=2cm@M=3mm{ \begin{tikzpicture} \filldraw[lightgray] (0,0) -- (2,0) -- (2,1) -- (0,1) -- cycle; \draw (0,0) -- (2,0); \draw (0,1) -- (2,1); \end{tikzpicture} \ar@{->>}[r] & \begin{tikzpicture} \draw[fill=lightgray] (0,0) ellipse (.5cm and .25cm); \filldraw[lightgray] (-.5,0) -- (.5,0) -- (.5, .6) -- (-.5, .6) -- cycle; \draw (-.5,0) -- (-.5, .6); \draw (.5,0) -- (.5, .6); \draw[fill=lightgray,yshift=.6cm] (0,0) ellipse (.5cm and .25cm); \end{tikzpicture} }$


as you can see the arrow is "too low".

• Sorry, I thought I linked it at the right page (27)... maybe the "#page=35" part can't be read by browser different from Chrome? May 27, 2012 at 18:23
• you can place nodes without matrix library. May 27, 2012 at 18:25
• I know, but I was wondering if there are some well-written solutions to this (quite natural if you handle geometric topology ;) ) problem... May 27, 2012 at 18:27
• You should be able to draw inside a TikZ matrix. See page 202 (introduction to matrices) in the manual. May 27, 2012 at 19:05
• Did I include the right image? Also matrix library is quite cooperative, what kind of difficulty did you have before? May 27, 2012 at 20:05

You can use tikz-cd. It is the tikz analog to xy-matrix, it easy to use, and it is reasonably flexible. Here is an example:

\documentclass{article}

\usepackage{tikz-cd}

\begin{document}

\pgfdeclareimage[interpolate=true]{image-name}{circle}

$$\begin{tikzcd} \pgfuseimage{image-name} \rar[start anchor=real east] & \node[draw,circle]{A}; \end{tikzcd}$$

\end{document}


Note that you need to modify the anchors of the arrows (where the arrows begin and end) since the anchors of the nodes in tikz-cd are shifted for technical reasons (cf. Sec. 3.3 in the package's manual). The circle on the left is a node as defined by tikz-cd, hence adjustment is necessary. The other is a normal node, so no adjustment is necessary.

Also, note that you can use pgf to include your drawings from separate files (since it seems you use several). This has the advantage that each image is included just once in the PDF file and it can be used many times without increasing the size of the file a lot.

Edit: Example Replace the polygons with fancier graphics, and you can get very nice diagrams with very simple code:

\documentclass{article}

\usepackage{tikz-cd}
\usetikzlibrary{shapes} % to draw polygons

\begin{document}

$\begin{tikzcd} \node[draw,regular polygon, regular polygon sides=5]{}; \rar{\varphi} \drar \arrow[bend right=50]{d} & \node[draw,circle]{}; \dlar[crossing over] \\ \node[draw,regular polygon, regular polygon sides=6]{}; \arrow{r}[description]{\psi} & \node[draw,circle]{}; \end{tikzcd}$

\end{document}


Also, I want to stress what I wrote in one comment, tikz-cd changes the arrows parameters (only in diagrams of course) for the arrows to look exactly as the arrows from the amsmath package. Very important...

• If you have the inner pictures, you don't need tikz-cd anyway. You can just use path-picture option on a node. Also tikz-cd loads TikZ so there is no need to load pgf. Aug 3, 2012 at 18:37
• It seems that if you don't load pgf explicitely you cannot use the command \pgfuseimage, at least in my installation. Aug 3, 2012 at 19:04
• Also, for the case-use of the OP, tikz-cd seems as a good choice since it provides an easy-to-use front-end to pgf/tikz for example to add labels and descriptions to arrows, cross-overs, control the curvature of the arrows and so on... But perhaps one of the nicests things it is that it modifies the parameters of the default arrows to make them exactly like the arrows from the amsmath package. I will add a more complicated example to show what I mean. Aug 3, 2012 at 19:08
• @percusse Actually, I was mistaken. Apparently my problem with the undefined command appeared because of loading pgf... Thanks, I have corrected my answer. Aug 3, 2012 at 20:16
• No problem, wha I meant in my slightly cocky comment is that the real challenge is to make readily made nodes that have those curves inside them for frequent use (at least that's how I read the question) otherwise you can't change the line width, color etc. (if you ever want that). Otherwise you solution is the practical way to go. Aug 3, 2012 at 20:32