[Tex/LaTex] Tikz for Commutative Diagrams

commutative-diagramstikz-cdtikz-pgf

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}

Best Answer

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}

enter image description here

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}

enter image description here