# Diagram displayed as an equation

Sorry to ask a direct question like that but: how can you do that ?

Is it a complicated use of align ? Is it really and equation (mathmode) ?

-

If you draw the diagram with TikZ, you can just but the tikzpicture into the equation environment. I believe that the same thing works for xy.

I guess the real question you are asking is how to draw a commutative diagram. Here is one way to do it with TikZ.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}

\begin{document}
$$\begin{tikzpicture}[baseline=-0.8ex] \matrix (m) [ matrix of math nodes, row sep=2em, column sep=4em, text height=1.5ex, text depth=0.25ex ] { x & x' \\ \hat x & \hat x' \\ }; \path[->] (m-1-1) edge node[above] {L} (m-1-2) (m-2-1) edge node[left] {T} (m-1-1) (m-2-2) edge node[right] {T} (m-1-2) (m-2-1) edge node[below] {R} (m-2-2); \end{tikzpicture}$$
\end{document}


Let's dissect this a bit:

• To draw a picture using TikZ, we use the tikzpicture environment. This environment can be used in math mode without problems.
• In the picture we first define a matrix with the vertices of the commutative diagram (using \matrix). Then we draw the arrows and label them (using \path).
• For the matrix, we give a name (m) and several options (the part in square brackets). Then we define the matrix like in the math command of that name (except that it is important to finish the last line with \\). The options do the following things:
• matrix of math nodes tells TikZ to interpret the code in the actual matrix in math mode (without it, TikZ would want to get drawing commands in the matrix).
• row sep and column sep set how much the the rows/columns should be spaced apart.
• text height and text depth set just that. This is useful for TikZ to figure out where the center of each cell should be (otherwise it would just center them in the apparent center, which is lower for x than for x').
• Normally one uses \draw to draw things in TikZ, but in this case \path works better.
• The -> tells TikZ to draw arrows instead of just normal lines.
• (m-i-j) accesses the cells of the matrix (labeled like in mathematics).
• A line is inserted with (start position) edge (end position).
• We want to add labels to the arrow. For this we use the node syntax. It inserts a node (=label) in the middle of the edge (or above, below,... it, depending on the options) with the text in curly brackets in it.
• Every drawing command must be finished with a semicolon ;.
• By default TeX puts the image on top of the baseline. We don't want that, because then the equation counter “(1)” wouldn't be centered. We use the baseline option to tell TikZ where the baseline of the surrounding text should be with respect to its internal coordinate system. As we didn't specify the position of the matrix, it's center is at (0,0) in TikZ's internal coordinate system. So baseline=0 would center the matrix around the baseline of the text/equation. This is better, but still not quite what we want, as we want the center to be on the centerline, i.e. on the height of the middle of the 1. So we move it up by 0.8ex, which corresponds to telling TikZ that the baseline should be at 0.8ex below 0.

• As egreg points out, for the centering one could also use gathered from amsmath instead of baseline shifting.

For more information on TikZ, see its manual. A good introduction to producing commutative diagrams with TikZ is ”Commutative Diagrams using TikZ”.

-
Thanks ! I tried with TikZ, have some good result, but with @egreg's answer the eq. number is properly centered. –  Cedric H. Apr 25 '11 at 20:35
@Cedric: You can change the anchoring of a TikZ diagram by using the option "baseline". For example, "\begin{tikzpicture}[baseline = (current bounding box)]" begins a vertically centered picture (this is suggested by the manual, somewhere). –  Ryan Reich Apr 25 '11 at 20:42
@Cedric: I didn't see your comment when typing the expanded answer. Well, just ignore everything except the last point then... –  Caramdir Apr 25 '11 at 20:47
Thanks a lot for the complete answer, I'll look at it in details I'll really learn something. –  Cedric H. Apr 25 '11 at 20:50

With Xy-pic it's quite easy

\usepackage{amsmath}
\usepackage[all,cmtip]{xypic}
\xyoption{pdf} % for pdflatex
...
\begin{document}
...
$$\label{commdiag} \begin{gathered} \xymatrix{ \mathbf{x} \ar[r]^{\mathbf{L}} & \mathbf{x}' \\ \hat{\mathbf{x}} \ar[r]_{\mathbf{R}} \ar[u]^{\mathbf{T}} & \hat{\mathbf{x}}' \ar[u]_{\mathbf{T}} } \end{gathered}$$


The gathered environment is used for centering correctly the equation number. If you really need longer horizontal arrows, write something like \xymatrix@C+12pt instead of \xymatrix (the +12pt is the extra length).

-
Great ! Is there a way to stretch the whole diagram to make it say 150% bigger ? –  Cedric H. Apr 25 '11 at 20:45
@Cedric: put \xymatrix{...} inside \scalebox{1.5}{\xymatrix{...}}, but I wouldn't recommend this. Rather use the @C and @R tricks to extend the arrows: for instance \xymatrix@C+24pt@R+12pt will lengthen horizontal arrows by 24pt and vertical arrows by 12pt –  egreg Apr 25 '11 at 20:58

I'd like to share with you a commutative diagram made with eplain:

\input eplain
\noindent Such a transformation can be represented by the commuting diagram
$$\varrowlength=1cm % Vertical arrow length \harrowlength=3cm % Horizontal arrow length \commdiag{ x & \mapright^L & x' \cr \mapup\lft T & & \mapup\rt T \cr \hat x & \mapright_R & \hat x' \cr } \eqno(1.6.4)$$
It must be pointed out that the concept of conjucation or matrices is of \dots
\bye


-