1

I want to draw the following figure in LaTeX using TikZ. How to I do that?

wanted

I tried with the code given below but there are still some errors.

Package pgfkeys Error: I do not know the key '/tikz/\protect \OT1\textellipsis ' and I am going to ignore it. Perhaps you misspelled it. \node[dotnode]

Extra \endcsname. \node[dotnode]

Missing \endcsname inserted. \node[dotnode]

How do I get rid of these errors and can the code be shortened further?

\documentclass{article}
\usepackage[margin=2cm]{geometry}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows.meta}
\tikzstyle{mynode}=[ellipse,draw,inner xsep=.2cm,inner ysep=.1cm]
\tikzstyle{dotnode}=[\dots]
\tikzstyle{toparrow}=[->,transform canvas={yshift=4pt}]
\tikzstyle{bottomarrow}=[->,transform canvas={yshift=-4pt}]

\begin{document}

\begin{tikzpicture}[line width=1pt,>={Straight   Barb[length=4pt,width=4pt]},shorten >=3pt,shorten <=3pt]
\node[mynode] (00) at (0,0) {$0,\color{blue}{0}$};
\node[mynode] (10) at (2.5,0) {$1,\color{blue}{0}$};
\node[mynode] (20) at (5,0) {$2,\color{blue}{0}$};
\node[dotnode] (30) at (7.5,0) {$\dots$};
\node[mynode] (40) at (10,0) {\tiny$ L_e(1),\color{blue}{0}$};
\node[mynode] (50) at (13.5,0) {\tiny $L_e(1)+1,\color{blue}{0}$};
\draw[toparrow] (00) to node[above] {$\lambda$} (10);
\draw[bottomarrow] (10) to node[below] {$\eta$} (00);
\draw[toparrow] (10) to node[above] {$\lambda$} (20);
\draw[bottomarrow] (20) to node[below] {$\eta$} (10);
\draw[toparrow] (20) to node[above] {$\lambda$} (30);
\draw[bottomarrow] (30) to node[below] {$\eta$} (20);
\draw[toparrow] (30) to node[above] {$\lambda$} (40);
\draw[bottomarrow] (40) to node[below] {$\eta$} (30);
\draw[toparrow] (40) to node[above] {$\lambda$} (50);
\draw[bottomarrow] (50) to node[below] {$\eta$} (40);
%
\node[mynode] (11) at (2.5,2) {$1,\color{red}{2}$};
\node[mynode] (21) at (5,2) {$2,\color{red}{2}$};
\node[dotnode] (31) at (7.5,2) {$\dots$};
\node[mynode] (41) at (10,2) {\tiny$ L_e(1), \color{red}{2}$};
\node[mynode] (51) at (13.5,2) {\tiny$ L_e(1)+1,\color{red}{2}$};
\node[mynode] (61) at (16.5,2) {\tiny$ L_e(1)+2,\color{red}{2}$};
\draw[toparrow] (11) to node[above] {$\lambda$} (21);
\draw[bottomarrow] (21) to node[below] {$\mu$} (11);
\draw[toparrow] (21) to node[above] {$\lambda$} (31);
\draw[bottomarrow] (31) to node[below] {$\mu$} (21);
\draw[toparrow] (31) to node[above] {$\lambda$} (41);
\draw[bottomarrow] (41) to node[below] {$\mu$} (31);
\draw[toparrow] (41) to node[above] {$\lambda$} (51);
\draw[bottomarrow] (51) to node[below] {$\mu$} (41);
\draw[toparrow] (51) to node[above] {$\lambda$} (61);
\draw[bottomarrow] (61) to node[below] {$\mu$} (51);
%
\node[mynode] (02) at (0,4) {$0,\color{blue}{0}$};
\node[mynode] (12) at (2.5,4) {$1,\color{blue}{0}$};
\node[mynode] (22) at (5,4) {$0,\color{blue}{0}$};
\node[dotnode] (32) at (7.5,4) {$\dots$};
\node[mynode] (42) at (10,4) {\tiny$ L_e(1),\color{blue}{0}$};
\node[mynode] (52) at (13.5,4) {\tiny$ L_e(1)+1,\color{blue}{0}$};
\draw[toparrow] (02) to node[above] {$\lambda$} (12);
\draw[toparrow] (12) to node[above] {$\lambda$} (22);
\draw[toparrow] (22) to node[above] {$\lambda$} (32);
\draw[toparrow] (32) to node[above] {$\lambda$} (42);
\draw[toparrow] (42) to node[above] {$\lambda$} (52);
\draw[->] (12) to node[right] {$\theta$} (11);
\draw[->] (22) to node[right] {$\theta$} (21);
\draw[->] (52) to node[right] {$\theta$} (51);
\draw[->] (42) to node[right] {$\theta$} (41);
%
\draw[->] (10) to node[right] {$\phi$} (11);
\draw[->] (20) to node[right] {$\phi$} (21);
\draw[->] (40) to node[right] {$\phi$} (41);
\draw[->] (50) to node[right] {$\phi$} (51);
\draw[->,draw=green] (11) to node[auto,swap] {$\bar p \mu$} (00);
\draw[->,draw=green] (11) to node[auto,swap] {$p \mu$} (02);
%
\draw[->,draw=green] (20) to node[auto,swap] {$\bar q \eta$} (11);
\draw[->,draw=green] (30) to node[auto,swap] {$\bar q \eta$} (21);
\draw[->,draw=green] (40) to node[auto,swap] {$\bar q \eta$} (31);
\draw[->,draw=green] (50) to node[auto,swap] {$\bar q \eta$} (41);
\end{tikzpicture}
\end{document}
3
  • 2
    Have you tried anything yet? Jan 6 '16 at 8:11
  • @Romain Picot I am a novice I want to learn the method of plotting using tikz-pgf. I went through the voluminous documentation, but couldn't get any idea to proceed.
    – Litun
    Jan 6 '16 at 8:16
  • @LitunJohn: From the documentation and tikz examples here are you able to at least create two nodes? Make some sort of attempt and post what you did and then ask a specific question. If you can't draw two nodes perhaps the first question should be how to draw to nodes and connect them? If you can draw to nodes and connect them, then the question is how to extend that. Jan 6 '16 at 8:54
1

The tikz-cd package, which provides the cd TikZ library was made specifically for drawing commutative diagrams. With this package the code becomes much smaller and, in my opinion, better readable. The arrows can be placed next to the label from which they emanate.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{cd,shapes,arrows.meta}
\begin{document}
\begin{tikzcd}[
  cells={nodes={draw,ellipse,inner sep=2pt,outer sep=2pt}},
  column sep=scriptsize,row sep=large,
  arrow style=tikz,
  diagrams={>={Straight Barb[length=4pt,width=4pt]}}
  ]
  % First line
  0,\color{green}1 \ar[r,"\lambda"] &
  1,\color{green}1 \ar[r,"\lambda"] \ar[d,"\theta"] &
  2,\color{green}1 \ar[r,"\lambda"] \ar[d,"\theta"] &
  |[draw=none]| \cdots \ar[r] &
  L_e(1),\color{green}1 \ar[r,"\lambda"] \ar[d,"\theta"] &
  L_e(1)+1,\color{green}1 \ar[d,"\theta"] \\
  % Second line
  &
  1,\color{red}2 \ar[r,"\lambda",shift left] \ar[lu,"p\mu",green] \ar[ld,"\bar{p}\mu",green] &
  2,\color{red}2 \ar[r,"\lambda",shift left] \ar[l,"\mu",shift left] &
  |[draw=none]| \cdots \ar[r,shift left] \ar[l,"\mu",shift left] &
  L_e(2),\color{red}2 \ar[r,"\lambda",shift left] \ar[l,shift left] &
  L_e(2)+1,\color{red}2 \ar[r,"\lambda",shift left] \ar[l,"\mu",shift left] &
  L_e(2)+2,\color{red}2 \ar[r,"\lambda",shift left] \ar[l,"\mu",shift left] &
  |[draw=none]| \cdots \ar[r,shift left] \ar[l,"\mu",shift left] &
  L_e(2),\color{red}2 \ar[r,"\lambda",shift left] \ar[l,shift left] &
  L_e(2)+1,\color{red}2 \ar[l,"\mu",shift left] \\
  % Third line
  0,\color{cyan}0 \ar[r,"\lambda",shift left] &
  1,\color{cyan}0 \ar[r,"\lambda",shift left] \ar[l,"\eta",shift left] \ar[u,"\phi"] &
  2,\color{cyan}0 \ar[r,"\lambda",shift left] \ar[l,"q\eta",shift left] \ar[u,"\phi"] \ar[lu,"\bar{q}\eta",green] &
  |[draw=none]| \cdots \ar[r,shift left] \ar[l,"q\eta",shift left] \ar[lu,"\bar{q}\eta",green] &
  L_e(1),\color{cyan}0 \ar[r,"\lambda",shift left] \ar[l,shift left] \ar[u,"\phi"] \ar[lu,"\bar{q}\eta",green] &
  L_e(1)+1,\color{cyan}0 \ar[l,"q\eta",shift left] \ar[u,"\phi"] \ar[lu,"\bar{q}\eta",green] \\
\end{tikzcd}
\end{document}

enter image description here

In my opinion, this image can be greatly improved by choosing slightly different options

\begin{tikzcd}[
  cells={nodes={draw=gray,thin,rectangle,rounded corners}},
  row sep=large
  ]

enter image description here

5
  • How to increase or decrease the size of the whole figure? I tried scale=0.5 in the tikzcd options, but only the arrows are reduced.
    – Litun
    Jan 7 '16 at 3:21
  • 1
    @LitunJohn See this question tex.stackexchange.com/questions/138984/… Jan 7 '16 at 7:20
  • I used the code cells={nodes={scale=0.5,draw=gray,thin,rectangle,rounded corners}}, row sep=large for reduced nodes. But the arrows sizes are unchanged. How to change the length of arrows? How to scale the whole figure by a single command?
    – Litun
    Jan 7 '16 at 8:20
  • Using {\small \begin{tikzcd}..................\end{tikzcd} } reduced the whole figure, but the arrow size was not proportionately reduced and the nodes are no more rectangular.
    – Litun
    Jan 7 '16 at 8:27
  • I did it by reading the tikzcd documentation.
    – Litun
    Jan 7 '16 at 9:58
7

Here's something, not in the most concise form, to get you started. In fact, I think almost all the commands you need for your diagram are here. Here's the code:

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{shapes,arrows.meta}

\tikzstyle{mynode}=[ellipse,draw,inner xsep=.3cm,inner ysep=.2cm]
\tikzstyle{toparrow}=[->,transform canvas={yshift=4pt}]
\tikzstyle{bottomarrow}=[->,transform canvas={yshift=-4pt}]

\begin{document}

\begin{tikzpicture}[line width=1pt,>={Straight Barb[length=5pt,width=5pt]},shorten >=3pt,shorten <=3pt]
\node[mynode] (00) at (0,0) {$0,\color{blue}{0}$};
\node[mynode] (10) at (3,0) {$1,\color{blue}{0}$};
\node[mynode] (11) at (3,2) {$1,\color{red}{2}$};
\draw[toparrow] (00) to node[above] {$\lambda$} (10);
\draw[bottomarrow] (10) to node[below] {$\eta$} (00);
\draw[->] (10) to node[right] {$\phi$} (11);
\draw[->,draw=green] (11) to node[auto,swap] {$\bar p \mu$} (00);
\end{tikzpicture}

\end{document}

And here's the output:

enter image description here

Now adjust the styles to fit your needs. Your colors may need adjusting, which you can do with the help of this question. Also, the three dots command is $\dots$ and the other Greek symbol is $\theta$.

The documentation for TikZ is indeed voluminous, but it is excellently organized and indexed, so I'm not convinced you went through all of it and didn't find what you need!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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