# Commutative diagram with matrices as objects

I would like to create a diagram which has matrices as objects and arrows between these matrices. In particular, I'd like to have four matrices, two matrices in the upper row, and two in the lower row, with four arrows between them.

I have drawn similar diagram with xymatrix, but I have no clue how to do this when the objects are themselves matrices.

Help is appreciated.

I tried working in the \xymatrix environment, and then use code like this:

$\left( \begin{array}{cc} 1 & b^{-1} \\ 0 & 1 \\ \end{array} \right)$


for the matrices, but this doesn't work.

• Welcome to TeX.SX! What did you try? – egreg Jan 28 '14 at 23:08
• Well I basically have no idea what to try... I know how to draw matrices, and how to draw commutative diagrams, but don't know how to put the two together. – Balerion_the_black Jan 28 '14 at 23:09
• Then show how you would do this. :) Then others can combine it for you (and correct anything in your approach if necessary.) – Svend Tveskæg Jan 28 '14 at 23:13
• Well I tried working in the \xymatrix environment, and then put something like this inside: [ \left( \begin{array}{cc} 1 & b^{-1} \\ 0 & 1 \\ \end{array} \right) ] But this does not work – Balerion_the_black Jan 28 '14 at 23:16
• Do you realy need the matrices explicitly present in the diagram? Instead of a full matrix, couldn't you just put something like A and elsewhere define the matrix A? Even if you do try to put in the full matrix, you shouldn't surround it with $ and $. Either leave it bare or surround it with \$s, whichever the xymatrix environment requires. – Dan Jan 28 '14 at 23:29

## 2 Answers

Using tikz-cd:

\documentclass{article}
\usepackage{tikz-cd}
\usepackage{amsmath}

\begin{document}

\begin{tikzcd}
\begin{pmatrix} 1 & a^{-1} \\ 0 & 1 \end{pmatrix}\arrow{r}{\phi}\arrow{d}{\eta} &
\begin{pmatrix} 1 & b^{-1} \\ 0 & 1 \end{pmatrix}\arrow{d}{\theta} \\
\begin{pmatrix} 1 & c^{-1} \\ 0 & 1 \end{pmatrix}\arrow{r}{\psi} &
\begin{pmatrix} 1 & d^{-1} \\ 0 & 1 \end{pmatrix} \\
\end{tikzcd}

\end{document} In my example I used bmatrix (from amsmath) to build the matrices; if you want to stick to array, some extra precautions with the management of the ampersand will be needed:

\documentclass{article}
\usepackage{tikz-cd}

\begin{document}

\begin{tikzcd}[ampersand replacement=\&]
\left(\begin{array}{cc} 1 & a^{-1} \\ 0 & 1 \end{array}\right)\arrow{r}{\phi}\arrow{d}{\eta} \&
\left(\begin{array}{cc} 1 & b^{-1} \\ 0 & 1 \end{array}\right)\arrow{d}{\theta} \\
\left(\begin{array}{cc} 1 & c^{-1} \\ 0 & 1 \end{array}\right)\arrow{r}{\psi} \&
\left(\begin{array}{cc} 1 & d^{-1} \\ 0 & 1 \end{array}\right) \\
\end{tikzcd}

\end{document} • How do I install the tikz-cd package? – Balerion_the_black Jan 28 '14 at 23:30
• Your LaTeX distribution should come with a package manager to do the installation automatically for you (tlmgr if you use TeX Live, and MiKTeX also has a package manager). Since tikz-cd is built upon pgf/tikz, you need those installed first and manual installation could be long and difficult. – Gonzalo Medina Jan 28 '14 at 23:33
• You could simplify the code using \rar and \dar (they are well hidden in the tikz-cd manual) – daleif Jan 28 '14 at 23:48
• @daleif yes I know the \rar, \dar, \ular, \urar and similar variants, but I prefer to use the long syntax \arrow{d}{}, \arrow{r}{}....;-) – Gonzalo Medina Jan 28 '14 at 23:53

Btw: matrices works just fine with \xymatrix just remember to hide the matrices from the xy parser:

\documentclass[a4paper]{memoir}
\usepackage{amsmath}
\usepackage[all]{xy}
\begin{document}
\begin{equation*}
\xymatrix{
{\begin{pmatrix}
a & b \\ c & d
\end{pmatrix}}
\ar[r] \ar[d]
&
{\begin{pmatrix}
a & b \\ c & d
\end{pmatrix}}
\ar[d]
\\
{\begin{pmatrix}
a & b \\ c & d
\end{pmatrix}}
\ar[r]
&
{\begin{pmatrix}
a & b \\ c & d
\end{pmatrix}}
}
\end{equation*}
\end{document} • Beat me by a minute. ;-) – egreg Jan 28 '14 at 23:44
• @egreg, thats why the picture is always added via an edit ;-) – daleif Jan 28 '14 at 23:45
• @egreg, btw: do you have ideas for tikz-cd such that one can use it inside say align without the need for ampersand replacement? – daleif Jan 28 '14 at 23:46
• No, ampersand replacement is unfortunately necessary, I'm afraid. – egreg Jan 29 '14 at 0:03
• Why? Xy seems to be able to handle it – daleif Jan 29 '14 at 8:10