2

I would like to draw state digram like this one: state diagram

I am using the following code:

\documentclass[tikz]{standalone}
\usetikzlibrary{automata,positioning}
\begin{document}
\begin{tikzpicture}
\node[state]                               (0) {0};
\node[state,right=of 0]                    (1) {1};
\node[state,right=of 1]                    (2) {2};
\coordinate[draw=none,right=of 2]          (2-g);
\node[state,right=of {2-g},text depth=0pt] (g) {g};

\draw[
    >=latex,
%   every node/.style={above,midway},% either
    auto=right,                      % or
    loop above/.style={out=75,in=105,loop},
    every loop,
    ]
     (g)   edge[loop above] node {$p_{gg}$}   (g)
       edge             node {$p_{gg-1}$} (2-g)
     (2-g) to               node {$p_{32}$}   (2)
       edge[loop above] node {$p_{22}$}   (2)
     (2)   edge             node {$p_{21}$}   (1)
     (1)   edge[loop above] node {$p_{11}$}   (1)
       edge             node {$p_{10}$}   (0)
     (0)   edge[loop above] node {$p_{00}$}   (0);
\end{tikzpicture}
\end{document}

But I would like have all arrows bidirectional. How can i do this? Thank you.

2
  • Please provide a minimal example in your question showing how you've tried to modify the code.
    – cfr
    Feb 25, 2016 at 2:10
  • edited. please have look now. Feb 25, 2016 at 2:15

1 Answer 1

5

We just need to adjust three styles:

  • the style of the path \draw draws;
  • the style of the edges \draw draws;
  • the style of the edge loops \draw draws.

We can append <-> to the \draw command and use .append style to do the same for the styles every loop and every edge:

  \draw[
    >=latex,
    auto=right,
    loop above/.style={out=75,in=105,loop},
    every loop/.append style={<->},
    every edge/.append style={<->},
    <->
  ]
  ...

double trouble

Complete code:

\documentclass[tikz,border=10pt,multi]{standalone}
\usetikzlibrary{automata,positioning}
\begin{document}
\begin{tikzpicture}
  \node[state]                               (0) {0};
  \node[state,right=of 0]                    (1) {1};
  \node[state,right=of 1]                    (2) {2};
  \coordinate[draw=none,right=of 2]          (2-g);
  \node[state,right=of {2-g},text depth=0pt] (g) {g};
  \draw[
    >=latex,
    auto=right,
    loop above/.style={out=75,in=105,loop},
    every loop/.append style={<->},
    every edge/.append style={<->},
    <->
  ]
  (g)   edge[loop above] node {$p_{gg}$}   (g)
  edge             node {$p_{gg-1}$} (2-g)
  (2-g) to               node {$p_{32}$}   (2)
  edge[loop above] node {$p_{22}$}   (2)
  (2)   edge             node {$p_{21}$}   (1)
  (1)   edge[loop above] node {$p_{11}$}   (1)
  edge             node {$p_{10}$}   (0)
  (0)   edge[loop above] node {$p_{00}$}   (0);
\end{tikzpicture}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .