Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
    
Welcome to TeX.SX! What did you try? –  egreg Jan 28 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 at 23:09
3  
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 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 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 at 23:29
add comment

2 Answers 2

up vote 7 down vote accepted

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}

enter image description here

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}

enter image description here

share|improve this answer
    
How do I install the tikz-cd package? –  Balerion_the_black Jan 28 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 at 23:33
1  
You could simplify the code using \rar and \dar (they are well hidden in the tikz-cd manual) –  daleif Jan 28 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 at 23:53
    
@GonzaloMedina Thanks a lot! –  Balerion_the_black Jan 29 at 0:46
add comment

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}

enter image description here

share|improve this answer
    
Beat me by a minute. ;-) –  egreg Jan 28 at 23:44
3  
@egreg, thats why the picture is always added via an edit ;-) –  daleif Jan 28 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 at 23:46
1  
No, ampersand replacement is unfortunately necessary, I'm afraid. –  egreg Jan 29 at 0:03
    
Why? Xy seems to be able to handle it –  daleif Jan 29 at 8:10
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.