I have the problem to create the following graph enter image description here

It should have the following style enter image description here

The code is given by

\newcommand{\N}{\mathbb{N}} % natuerliche Zahlen
    \newcommand{\Z}{\mathbb{Z}} % ganze Zahlen
    \newcommand{\Q}{\mathbb{Q}} % rationale Zahlen
    \newcommand{\R}{\mathbb{R}} % reelle Zahlen
    \newcommand{\Prob}{\mathbb{P}} % Symbol fuer Wahrscheinlichkeitsmaß
    \newcommand{\E}{\mathbb{E}} % Symbol fuer Erwartungswert
    \newcommand{\QSo}{\mathbf{Q}_{S' S'}}
    \newcommand{\QSot}{\mathbf{Q}_{S' S''}}
    \newcommand{\QSt}{\mathbf{Q}_{S'' S''}}

    \begin{tikzpicture}[->,>=stealth,shorten >=1pt,auto,node distance=2.5cm,
      \tikzset{every state/.append style={fill=red,draw=none,text=white}}

      \node[state]         (A)                    {$\{\omega\}$};
      \node[state]         (B) [below=of A] {$A_{2}(1)$};
      \node[state]         (C) [below=of B] {$A_{1}(1)$};
      \node[state]         (D) [below=of C] {$\{\omega\}$};
      \node[state]         (F) [right=of B] {$A_{2}(2)$};
      \node[state]         (E) [above=of F] {$\{\omega\}$};
      \node[state]         (G) [below=of F] {$A_{1}(2)$};
      \node[state]         (H) [below=of G] {$\{\omega\}$};
      \node[state]         (J) [right=of F] {$A_{2}(m)$};
      \node[state]         (I) [above=of J] {$\{\omega\}$};
      \node[state]         (K) [below=of J] {$A_{1}(m)$};
      \node[state]         (L) [below=of K] {$\{\omega\}$};
      \node[state]         (M) [right=of J] {$A_{2}$\scriptsize(m+1)};

      \path (B) edge              node {$\mathbf{Q}_{A_{2}\{\omega\}}$} (A)
                edge [loop left]  node {$\QAt$}                         (B)
                edge              node {$\QAto$}                        (C)
            (C) edge [loop left]  node {$\QAo$}                         (C)
                edge              node {$\mathbf{Q}_{A_{1}\{\omega\}}$} (D)
                edge [right]      node {$\QAot$}                        (F)
            (F) edge              node {$\mathbf{Q}_{A_{2}\{\omega\}}$} (E)
                edge [loop left]  node {$\QAt$}                         (F)
                edge              node(aux) {$\QAto$}                        (G)
            (G) edge [loop left]  node {$\QAo$}                         (G)
                edge              node {$\mathbf{Q}_{A_{1}\{\omega\}}$} (H)
            (J) edge              node {$\mathbf{Q}_{A_{2}\{\omega\}}$} (I)
                edge [loop left]  node {$\QAt$}                         (J)
                edge              node {$\QAto$}                        (K)
            (K) edge [loop left]  node {$\QAo$}                         (K)
                edge              node {$\mathbf{Q}_{A_{1}\{\omega\}}$} (L)
                edge [right]      node {$\QAot$}                        (M)
            (M) edge [loop left]  node {$\I$}                           (M);
     \node[right=2mm of aux,font=\bfseries\Huge]{\dots};

Thanks for any help

  • It would be helpful if you composed a fully compilable minimal working example (MWE) including \documentclass and the appropriate packages that sets up the problem. While solving problems can be fun, setting them up is not. Then, those trying to help can simply cut and paste your MWE and get started on solving the problem. – samcarter is at topanswers.xyz Jan 4 '19 at 16:49
  • I'am Sorry...I have edited my question – wayne Jan 4 '19 at 17:49
  • 1
    Unfortunately your code does not compile, there is no documentclass etc. – samcarter is at topanswers.xyz Jan 4 '19 at 17:52
  • Why is this so important for you? I only want to create the graph at the top using tikz – wayne Jan 4 '19 at 17:54
  • 2
    A working example gives the people who are trying to help you something to start with. Setting up a document boring and might deter people from starting to solve your problem. – samcarter is at topanswers.xyz Jan 4 '19 at 18:04

Here is some starting point:

\documentclass[tikz, border=3mm]{standalone}


  node distance = 14mm,
  start chain = going right,
  state/.append style = {
      minimum width=3em,
      on chain,

\node (s0)[state]    {$1$};   
\node (s1)[state]    {$2$};  
\node (s2)[state]    {$3$};  
\node (s3)[state]    {$r-2$};  
\node (s4)[state]    {$r-1$};     

\draw[->] (s0) edge[bend left] node (a1) {p} (s1)
          (s1) edge[bend left] node (b1) {q} (s0)
          (s1) edge[bend left] node (a2) {p} (s2)
          (s2) edge[bend left] node (b2) {q} (s1)
          (s3) edge[bend left] node (a4) {p} (s4)
          (s4) edge[bend left] node (b4) {q} (s3)

\node[state,node distance=3cm] (a) [below=of s2] {$\alpha$};      
\draw[->] (s4.south west) edge node {p} (a); 
\draw[<-] (a) edge node {q} (s0.south east); 
\node[node distance=0.3cm,right=of s2] {$\ldots$};  
\path (a) edge [loop below] node {Q} (a);    



enter image description here

  • 1
    @wayne In your graph at the top, there is no loop - and the code of the other one is still not compilable. – samcarter is at topanswers.xyz Jan 4 '19 at 19:41
  • 1
    @wayne Just stick \node{p} into the obvious place (that is, before the end point (a)) in the last two \draw commands. That may not do what you want perfectly, so tweak the positioning of the nodes a bit by saying something like \node[below], \node[below=2pt] (moving them 2pt further from the anchor point), or perhaps \node[below left] and \node[below right]. But really, what you were given is explicitly a starting point. The purpose of this site is not to get other people to do your work for you. Rather, it is to get people unstuck when they're stuck. – Harald Hanche-Olsen Jan 5 '19 at 11:35
  • 2
    @wayne My motivation to invest further work in this answer is very low. There is still no compilable example in your answer and for most of your previous questions users gave you nice answers, but you did not mark any of them as accepted. – samcarter is at topanswers.xyz Jan 5 '19 at 13:03
  • 1
    @wayne Thanks for accepting the answers to your previous questions! In exchange I added some p and q. – samcarter is at topanswers.xyz Jan 5 '19 at 14:00
  • 1
    @wayne Will you make the code in your question compilable? – samcarter is at topanswers.xyz Jan 5 '19 at 14:24

EDIT: a new version. I have done some changes. You can change the size the character similary where there are a large p and and large 1.

enter image description here

\usepackage{tikz, tikz-cd,amsmath}
            \node[shape=circle, draw=red, fill=red, draw,inner sep=7pt] (char) {#1};}}
\begin{tikzcd}[column sep=1.6in,row sep=1.1in]
\nci{\textcolor{white}{\resizebox{.5cm}{!}{1}}}\arrow[r, "\resizebox{.5cm}{!}{$p$}", bend left=15] \arrow[rrd, "q"'] & \nci{\textcolor{white}{2}} \arrow[l, "q", bend left=15] \arrow[r, "p", bend left=15] & \nci{\textcolor{white}{3}}\cdots  \arrow[l, "q", bend left=15] & \qquad \cdots \nci{\textcolor{white}{$r-2$}} \arrow[r, "p", bend left=10] & \nci{\textcolor{white}{$r-1$}} \arrow[lld, "p"'] \arrow[l, "q", bend left=10] \\
  &  & \alpha &  & 

Here a version with tikz-cd simply to compare with what you want. Of course you can increase the size of the characters etc.

enter image description here


\begin{tikzcd}[column sep=1.6in,row sep=1.1in]
1 \arrow[r, "p", bend left=15] \arrow[rrd, "q"'] & 2 \arrow[l, "q", bend left=15] \arrow[r, "p", bend left=15] & 3\cdots  \arrow[l, "q", bend left=15] & \qquad \cdots r-2 \arrow[r, "p", bend left=10] & r-1 \arrow[lld, "p"'] \arrow[l, "q", bend left=10] \\
  &  & \alpha &  & 
  • It does not compile. Can you please add the code using tikzpicture – wayne Jan 4 '19 at 18:01
  • 2
    @wayne it compiles fine for me on a current texlive2018. Did you actually tried? – Ulrike Fischer Jan 4 '19 at 20:03

Here is a solution that uses the chain concept with TikZ (see section 19 from page 257 of 3.0.1a manual). The first string defines nodes 1; 2; 3; ...; n-1 and n-2. The second chain reuses these nodes and places the arrows in the opposite direction.



\graph[grow right=20mm,edges=bend left,edge node={node [yshift=3pt, midway]{p}}] {
1 -> 2   -> 3-!-4/$\cdots$   -!- 5/{$n-2$}->6/{$n-1$}  ;
\graph[use existing nodes,edges=bend right,grow right=20mm,edge node={node [yshift=3pt, midway]{q}}]  {
1 <- 2   <- 3-!-4/$\cdots$   -!- 5/{$n-2$}<-6/{$n-1$}  ;
\node at (5,-2)(a){a}edge [loop below] node {s} ();;
\graph[use existing nodes,edges={bend right=10}]{ 1.south->[edge label'=q](a)<-[edge label=p]6.south;};
  • how can I add a loop to the node $a$? – wayne Jan 4 '19 at 19:18
  • A loop up or down? – AndréC Jan 4 '19 at 19:25
  • I added a loop below node $a$ – AndréC Jan 4 '19 at 19:29

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.