16

I am quite new to LaTeX and I was curious if anyone knew how to make these sorts of diagrams. I saw one other picture on here but it was a three node diagram and I wasn't sure how to make LaTeX recognize to make a square when I inserted another node. Any ideas?

Edit: Specifically, this works:

\begin{tikzpicture}[every node/.style={midway}]
\matrix[column sep={4em,between origins},
        row sep={2em}] at (0,0)
{ \node(R)   {$R$}  ; & \node(S) {$S$}; \\
  \node(R/I) {$R/I$};                   \\};
\draw[<-] (R/I) -- (R) node[anchor=east]  {$\chi$};
\draw[->] (R/I) -- (S) node[anchor=north]  {$\psi$};
\draw[->] (R)   -- (S) node[anchor=south] {$\phi$};
\end{tikzpicture}

But I need to change the starting points and destinations of arrows to allow for four nodes.

ShreevatsaR
  • 45,428
  • 10
  • 117
  • 149
user33311
  • 181
  • 1
    Welcome to TeX.SX! Please add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – Herr K. Jul 06 '13 at 16:00
  • Is this answer (http://tex.stackexchange.com/a/45747/12571) useful? – JLDiaz Jul 06 '13 at 16:01
  • 1
    Also, there is a TikZ-based package specifically for commutative diagrams: tikz-cd – Herr K. Jul 06 '13 at 16:01
  • Yes JLDiaz, but for some reason even though I have the tikz package up and running when I paste that into my code it won't compile. – user33311 Jul 06 '13 at 16:02
  • I will definitely keep that in mind as I use these more, Kevin. Is that a default package? – user33311 Jul 06 '13 at 16:04
  • @user33311 Be sure to include tikz library matrix. If still does not work post a new question and include the errors you get. – JLDiaz Jul 06 '13 at 16:10
  • @JLDiaz I just posted code from the linked article that works well for me. Is there an easy way to edit this for four nodes? – user33311 Jul 06 '13 at 16:11
  • 1
    @user33311 What you put inside the \matrix has the structure of a latex table, so you use & to make "cells" in each column, and \\ to start a new row. So you can guess that you need to add the fourth node by adding & \node{...} in the code your posted, in the white space below node S. – JLDiaz Jul 06 '13 at 16:21
  • Thank you, I should have seen that, it worked perfectly. – user33311 Jul 06 '13 at 16:33

2 Answers2

24

It's really easy with tikz-cd:

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

\begin{document}

\[
\begin{tikzcd}
R \arrow{r}{\phi} \arrow[swap]{d}{\chi} & S \arrow{d}{\Psi} \\
R/I \arrow{ur}{\psi} \arrow{r}{\Phi} & T
\end{tikzcd}
\]

\end{document}

enter image description here

David Carlisle
  • 757,742
egreg
  • 1,121,712
4

As JLDiaz informed you, we can make a forth node by adding an & \node ...;

\documentclass[convert = false, tikz]{standalone}
\begin{document}
\begin{tikzpicture}[every node/.style={midway}]
  \matrix[column sep={4em,between origins}, row sep={2em}] at (0,0) {
    \node(R) {$R$}  ; & \node(S) {$S$}; \\
    \node(R/I) {$R/I$}; & \node (T) {$T$};\\
  };
  \draw[<-] (R/I) -- (R) node[anchor=east]  {$\chi$};
  \draw[->] (R/I) -- (S) node[anchor=north]  {$\psi$};
  \draw[->] (R) -- (S) node[anchor=south] {$\phi$};
  \draw[->] (S) -- (T) node[anchor=west] {$\Psi$};
  \draw[->] (R/I) -- (T) node[anchor=north] {$\Phi$};
\end{tikzpicture}
\end{document}

enter image description here

dustin
  • 18,617
  • 23
  • 99
  • 204