4

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}
Troy
  • 13,741

2 Answers2

8

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

Moriambar
  • 11,466
Gonzalo Medina
  • 505,128
  • 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 09 '13 at 15:00
  • And does it mean i have to first uninstall the current version? – olurodekaa Apr 09 '13 at 15:01
  • 1
    @user28756 Yes. tikz-cd is part of MiKTeX, so it ships with the complete installatiion. – Gonzalo Medina Apr 09 '13 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 09 '13 at 15:04
  • @user28756 which version do you have currently installed? – Gonzalo Medina Apr 09 '13 at 15:04
  • I've installed the latest version now. It's working but i've got some syntax problems. I need to draw a 3-node diagram with all the nodes on the same row – olurodekaa Apr 11 '13 at 05:50
  • I've installed the latest version now. It's working but i've got some syntax problems. I need to draw a 3-node (nodes K, L, M)diagram with all the nodes on the same row. One arrow joins K and L, and there are 2 parallel arrows in between L and M (one pointing from L to M(say 'a') and the other one below it and pointing in the reverse direction-say 'b'). Each of the 3 arrows has a label. I need a help please! When i tried it, the 1st arrow is ok BUT the labels on the arrows between L and M overlap and the other arrow from M to L ('b') is wrongly placed in-between K and L, pointing from L to K. – olurodekaa Apr 11 '13 at 06:05
  • I've just read cgnieder's answer to the Question tagged {tikz-pg}4108 {diagrams}438. Then i typset as follows: \documentclass[12pt]{book} \usepackage{tikz-cd} \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}. The only problem left is that the labels alpha and beta are lumped together. Please how can i position the labels separated properly.Thanks.
    – olurodekaa Apr 11 '13 at 07:53
  • 1
    @user28756 please see my updated answer. – Gonzalo Medina Apr 11 '13 at 12:50
  • @user28756 don't forget that around here we thank by up-voting good answers and accepting the one that best solved your problem (up-voting and accepting are two different actions). In case of doubt, please see [`How do you accept an answer?](http://meta.tex.stackexchange.com/q/1852/3954). – Gonzalo Medina Apr 11 '13 at 12:59
3

With PSTricks.

enter image description here

\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:

enter image description here

\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}
Moriambar
  • 11,466