Sign up ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I would create using tikz package this Markov chain but I encountered many problems. Who can post the right code to create the follow Markov chain?

enter image description here

share|improve this question
I can! What are your problems? What have you tried? Where have you failed? – Qrrbrbirlbel Jan 7 '13 at 1:14
Usually all the nodes have to be connect among them...but in this case the last node at the right is not connected to anyone!! – Mazzy Jan 7 '13 at 1:15
There are lots of automata drawing questions on the site. Start here: Which package can be used to draw automata?. If you already have some code, post it (complete document, not a fragment) and then we can help you. – Alan Munn Jan 7 '13 at 1:19
Without a MWE one can hardly guess what’s wrong. It seems like you have placed a node between 2 and g but without any content or draw. You probably meant to use a coordinate. – Qrrbrbirlbel Jan 7 '13 at 1:19
To any down voters: we regularly get these type of draw-this-for-me question on the site; one down vote is enough. Please see… for further discussion – cmhughes Jan 7 '13 at 1:56

1 Answer 1

up vote 9 down vote accepted

The positioning library


\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};

%   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);


enter image description here

Replacing the \coordinate line with

\node[draw=none,right=of 2]           (2-g) {text};

you get:

enter image description here

The chains library


\begin{tikzpicture}[start chain=going right]
\node[state, on chain]                 (0) {0};
\node[state, on chain]                 (1) {1};
\node[state, on chain]                 (2) {2};
\node[on chain]                   (2-g) {text};
\node[state, on chain, text depth=0pt] (g) {g};

% The \draw path is like the one above.


enter image description here

share|improve this answer
Oh thanks you so are so nice!!!THanks for having dedicate your free time to me!!! – Mazzy Jan 7 '13 at 1:42
@Mazzy while you're thanking people, you might want to check your other questions and accept some more of the answers that helped you. – Alan Munn Jan 7 '13 at 1:45
is It possible to add some text among the two state 2 and g. I would add ... among those two states. I tried using \text{...} but It gave me error – Mazzy Jan 7 '13 at 1:54
@AlanMunn If some questions are not accepted, this means they wasn't right for me...Not all the ans can be useful – Mazzy Jan 7 '13 at 1:55
@Mazzy \text is, unless otherwise defined, a math-mode macro defined by amstext that allows to pick up the text font outside the current math mode. You could place your usual \node, just like the others, replacing the \coordinate with \node[right=of 2] (2-g) {<text>};. See my updated answer. – Qrrbrbirlbel Jan 7 '13 at 1:59

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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