# Tikz for Commutative Diagrams

I need to use tikz package because of the quality of commutative diagrams it produces as I've seen in some manuals. I've tried it severally but all to no avail. I'm using MiKTeX with TeXmaker editor on windows. The MiKTeX was installed last year september (2012). I'll like to know

1. if I need to install any specific package or need to install the latest version of MiKTeX
2. exactly what and and what do I need to specify or include in my preamble, bearing it in mind that the document I'm writing is a thesis in algebraic category.

\documentclass[12pt]{book}
\usepackage{amsmath,amssymb,amsthm,latexsym}
\usepackage{tikz-cd}
\usetikzlibrary{matrix,arrows}

\begin{document}

\begin{tikzcd}[column sep = 1.3cm]
K
\arrow{r}{\kappa}
& L
\arrow[transform canvas = {yshift = 0.7ex}]{r}{\alpha}
\arrow[transform canvas = {yshift = -0.7ex},leftarrow]
{r}{\beta}
& M
\end{tikzcd}
\end{document}

-
Better to have the latest MiKTeX version installed. The tikz-cd package is your friend for the commutative diagrams. –  Gonzalo Medina Apr 9 at 14:49
Tikz based package mentioned is important than Editor and Distribution for generating diagramms. –  texenthusiast Apr 11 at 12:30

I would recommend the tikz-cd package for your commutative diagrams; the package documentation contains examples, like the one for the next example:

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

\begin{document}

\begin{tikzcd}[row sep=scriptsize, column sep=scriptsize]
& f^* E_V \arrow{dl}\arrow{rr}\arrow{dd} & & E_V \arrow{dl}\arrow{dd} \\
f^* E \arrow[crossing over]{rr}\arrow{dd} & & E \\
& U \arrow{dl}\arrow{rr} & & V \arrow{dl} \\
M \arrow{rr} & & N\arrow[crossing over, leftarrow]{uu}\\
\end{tikzcd}

\end{document}


Regarding your LaTeX system, the best thing is to keep your installation updated. Install the latest MiKTeX version and do a complete installation, not just the basic MiKTeX installation.

Regarding the problem mentioned, in a comment, you can use swap to change the position for the label for the arrow:

\documentclass[12pt]{book}
\usepackage{amsmath,amssymb,amsthm,latexsym}
\usepackage{tikz-cd}
\usetikzlibrary{matrix,arrows}

\begin{document}

\begin{tikzcd}[column sep = 1.3cm]
K
\arrow{r}{\kappa}
& L
\arrow[transform canvas={yshift = 0.7ex}]{r}{\alpha}
\arrow[transform canvas={yshift = -0.3ex},leftarrow,swap]
{r}{\beta}
& M
\end{tikzcd}

\end{document}


-
Really glad with swift response.But once i install the complete latest version of MikTeX, will tikz-cd be automatically included and resove my problem? –  olurodekaa Apr 9 at 15:00
And does it mean i have to first uninstall the current version? –  olurodekaa Apr 9 at 15:01
@user28756 Yes. tikz-cd is part of MiKTeX, so it ships with the complete installatiion. –  Gonzalo Medina Apr 9 at 15:02
@user28756 to your second question: if you're going to install a new version, I think so, but I don't know for sure since I don't use MiKTeX. Check the MiKTeX site. –  Gonzalo Medina Apr 9 at 15:04
@user28756 please see my updated answer. –  Gonzalo Medina Apr 11 at 12:50

With PSTricks.

\documentclass[preview,border=12pt]{standalone}
\usepackage{pst-node}
\psset{rowsep=1,colsep}
\begin{document}
\offinterlineskip
$\psmatrix & f^*E_v& & E_v\\ f^*E& & E& \\ & U& & V\\ M& & N& \endpsmatrix \everypsbox{\scriptstyle} \psset{arrows=->,nodesep=3pt,border=3pt} \ncline{1,2}{1,4} \ncline{1,2}{2,1} \ncline{1,4}{2,3} \ncline{2,1}{4,1} \ncline{1,2}{3,2} \ncline{1,4}{3,4} \ncline{2,1}{2,3} \ncline{3,2}{4,1} \ncline{3,2}{3,4} \ncline{3,4}{4,3} \ncline{4,1}{4,3} \ncline{2,3}{4,3}$
\end{document}


## For double lines and labels:

\documentclass[preview,border=12pt]{standalone}
\usepackage{pst-node}
\psset{rowsep=1,colsep}
\begin{document}
\offinterlineskip
$\psmatrix & f^*E_v& & E_v\\ f^*E& & E& \\ & U& & V\\ M& & N& \endpsmatrix \everypsbox{\scriptstyle} \psset{arrows=->,nodesep=3pt,border=2pt,shortput=tablr,labelsep=2pt} \ncline[offset=2pt]{1,2}{1,4}^{a} \ncline[offset=-2pt,arrows=<-]{1,2}{1,4}_{b} \ncline{1,2}{2,1} \ncline{1,4}{2,3} \ncline{2,1}{4,1} \ncline{1,2}{3,2} \ncline{1,4}{3,4} \ncline{2,1}{2,3} \ncline{3,2}{4,1} \ncline{3,2}{3,4} \ncline{3,4}{4,3} \ncline{4,1}{4,3} \ncline{2,3}{4,3}$
\end{document}

-