1

I am trying to draw the following diagram in TikZ:

Their image

My attempt looks like this (note the node labels are slightly different but that's not my problem!):

my attempt

My code is the following:

\documentclass[11pt,a4paper]{report}

\usepackage[USenglish]{babel} 
\usepackage[T1]{fontenc}
\usepackage[ansinew]{inputenc}
\usepackage{lmodern} 

\usepackage{tikz}

\usetikzlibrary{positioning,fit,backgrounds,arrows,shapes,automata,petri}

\tikzset{
    place/.style={
        circle,
        thick,
        minimum size=6mm,
                draw
    },
    transitionV/.style={
        rectangle,
        thick,
        fill=black,
        minimum height=6mm,
        inner xsep=1pt
    }
}

\begin{document}

\title{Test}
\author{Me}
\date{\today}
\begin{figure}[h!]
\centering
\begin{tikzpicture}[node distance=1cm and 2cm,>=stealth',bend     angle=45,thick]
        \node [transitionV,label=above:$q_1$] (q1) {};
        \node [place,tokens=1,label=above:$\alpha_{11}(k)$] (p11) [below= of q1] {}
            edge[pre,bend right,overlay] (q1)
            edge[post,bend left,overlay] (q1);
        \node [place,tokens=2,label=above:$\alpha_{41}(k)$] (p41) [below right=0.25cm and 2cm of q1] {}
            edge[pre] (q1);
        \node [transitionV,label=above:$q_4$] (q4) [below right=0.25cm and 2cm of p41] {}
            edge[pre] (p41);
        \node [place,label=above:$\alpha_{24}(k)$] (p24) [above right=0.25cm and 2cm of q4] {}
            edge[pre] (q4);
        \node [transitionV,label=above:$q_2$] (q2) [above right=0.25cm and 2cm of p24] {}
                edge[pre] (p24);
        \node [place,tokens=1,label=above:$\alpha_{22}(k)$] (p22) [below= of q2] {}
                edge[pre,bend right,overlay] (q2)
                edge[post,bend left,overlay] (q2);
        \node [place,tokens=1,label=above:$\alpha_{31}(k)$] (p31) [above right=0.25cm and 2cm of q1] {}
                edge[pre] (q1);
        \node [transitionV,label=below:$q_3$] (q3) [above right=0.25cm and 2cm of p31] {}
            edge[pre] (p31);
        \node [place,label=above:$\alpha_{23}(k)$] (p23) [below right=0.25cm and 2cm of q3] {}
                edge[pre] (q3)
                edge[post] (q2);
        \node [place,tokens=1,label=below:$\alpha_{12}(k)$] (p12) [above= of q3] {}
                edge[pre,bend left,out=45,in=45,looseness=1.2] (q2)
                edge[post,bend left,out=315,in=315,looseness=1.2] (q1);
\end{tikzpicture}
\caption{Event graph}
\end{figure}

\end{document}

I've exhausted my knowledge of TikZ. Please could someone tell me how I could get my diagram looking nice like the example above? Thanks!

3

Please ask specific questions of what you want to have, what you have tried, and where you have failed to reach that. Like it stands now, it is no research value for this site and just a "do it for me" post.

I corrected the two main issues I have seen. The rest should be self explanatory from the code you already have.

% arara: pdflatex

\documentclass[11pt,a4paper]{report}
\usepackage[USenglish]{babel} 
\usepackage[T1]{fontenc}
\usepackage[ansinew]{inputenc}
\usepackage{lmodern} 
\usepackage{tikz}
\usetikzlibrary{positioning,arrows,petri}

\tikzset{
    place/.style={
        circle,
        thick,
        minimum size=6mm,
        draw
    },
    transitionV/.style={
        rectangle,
        thick,
        fill=black,
        minimum height=6mm,
        inner xsep=1pt
    }
}

\begin{document}
    \begin{figure}[h!]
        \centering
        \begin{tikzpicture}[node distance=1cm and 2cm,>=stealth',bend angle=45,thick]
        \node [transitionV,label=above:$q_1$] (q1) {};
        \node [place,tokens=1,label=above:$\alpha_{11}(k)$] (p11) [below= of q1] {}
        edge[pre,bend right=70] (q1)
        edge[post,bend left=70] (q1);
        \node [place,tokens=2,label=above:$\alpha_{41}(k)$] (p41) [below right=0.25cm and 2cm of q1] {}
        edge[pre] (q1);
        \node [transitionV,label=above:$q_4$] (q4) [below right=0.25cm and 2cm of p41] {}
        edge[pre] (p41);
        \node [place,label=above:$\alpha_{24}(k)$] (p24) [above right=0.25cm and 2cm of q4] {}
        edge[pre] (q4);
        \node [transitionV,label=above:$q_2$] (q2) [above right=0.25cm and 2cm of p24] {}
        edge[pre] (p24);
        \node [place,tokens=1,label=above:$\alpha_{22}(k)$] (p22) [below= of q2] {}
        edge[pre,bend right=70] (q2)
        edge[post,bend left=70] (q2);
        \node [place,tokens=1,label=above:$\alpha_{31}(k)$] (p31) [above right=0.25cm and 2cm of q1] {}
        edge[pre] (q1);
        \node [transitionV,label=below:$q_3$] (q3) [above right=0.25cm and 2cm of p31] {}
        edge[pre] (p31);
        \node [place,label=above:$\alpha_{23}(k)$] (p23) [below right=0.25cm and 2cm of q3] {}
        edge[pre] (q3)
        edge[post] (q2);
        \node [place,tokens=1,label=below:$\alpha_{12}(k)$] (p12) [above= of q3] {}
        edge[pre,out=0,in=20,,looseness=1.2] (q2)
        edge[post,out=180,in=160,looseness=1.2] (q1);
        \end{tikzpicture}
        \caption{Event graph}
    \end{figure}    
\end{document}

enter image description here

  • Why not putting alpha_12 in the middle of q1, q2, q3 and q4? It will look better. – Astrinus Apr 30 '15 at 15:19
  • @Astrinus For sure, but you should ask that to the OP. – LaRiFaRi Apr 30 '15 at 15:20
  • The main problems are the bendy arrows which you appear to have fixed. The other issues are the lines crossing at q1 and q2 - how do I get lines joining the transition bar at different points along its side? @Astrinus yes, I suppose I could do, thanks! – Tom Offer Apr 30 '15 at 15:26
  • @TomOffer With in and out. – LaRiFaRi Apr 30 '15 at 16:50
  • 1
    @TomOffer yes and therefore also the anchor to the node. If you arrive under 45°, it will be situated much more to the edge. If this is not enough, you may use an yshift=<distance> – LaRiFaRi Apr 30 '15 at 23:34
3

In my attempt I modified your code by separating the nodes from the paths, and using arc paths for drawing the small ones on the sides. This is because I think a better organised code is easier to understand and every time I write/finish some code, I take a couple of minutes to fix its structure and remove redundant options.

The lines join at different paths by using anchors and in this case I had to add calc in order to calculate other positions to achieve it. So for example if you have (q2.west) and (q2.south west), in order to calculate the middle point, you would write ($(q2.west)!.5!(q2.south west)$), this way your arrow can connect to the middle point between the west and the south west of a certain node.

All paths have also been shortened as per your desired example. The bending library has been added as well in order for the tips on the arc arrows to be properly aligned.

Output

figure 1

Code

\documentclass[11pt,a4paper]{report}
\usepackage[USenglish]{babel}
\usepackage[T1]{fontenc}
\usepackage[ansinew]{inputenc}
\usepackage{lmodern}
\usepackage{tikz}

\usetikzlibrary{positioning,fit,backgrounds,arrows,shapes,automata,petri,calc,bending}

\tikzset{
    place/.style={
        circle,
        thick,
        minimum size=6mm,
                draw
    },
    transitionV/.style={
        rectangle,
        thick,
        fill=black,
        minimum height=6mm,
        inner xsep=1pt
    }
}

\begin{document}

\title{Test}
\author{Me}
\date{\today}

\begin{figure}[h!]
\centering
\begin{tikzpicture}[
    node distance=1cm and 2cm,
    >=stealth',
    bend angle=#1,
    thick,
  shorten >=2pt,
  shorten <=2pt
    ]

% Nodes
    \node [transitionV,label=above:$q_1$] (q1) {};
    \node [place,tokens=1,label=above:$\alpha_{11}(k)$] (p11) [below= of q1] {};
    \node [place,tokens=2,label=above:$\alpha_{41}(k)$] (p41) [below right=0.25cm and 2cm of q1] {};
    \node [transitionV,label=above:$q_4$] (q4) [below right=0.25cm and 2cm of p41] {};
    \node [place,label=above:$\alpha_{24}(k)$] (p24) [above right=0.25cm and 2cm of q4] {};
    \node [transitionV,label=above:$q_2$] (q2) [above right=0.25cm and 2cm of p24] {};
    \node [place,tokens=1,label=above:$\alpha_{22}(k)$] (p22) [below= of q2] {};
    \node [place,tokens=1,label=above:$\alpha_{31}(k)$] (p31) [above right=0.25cm and 2cm of q1] {};
    \node [transitionV,label=below:$q_3$] (q3) [above right=0.25cm and 2cm of p31] {};
    \node [place,label=above:$\alpha_{23}(k)$] (p23) [below right=0.25cm and 2cm of q3] {};
    \node [place,tokens=1,label=below:$\alpha_{12}(k)$] (p12) [above= of q3] {};

% Paths

  % left
    \draw ($(q1.north east)!.5!(q1.east)$) edge[bend left=15,->] (p31);
  \draw (q1.east) edge[bend right=15,->] (p41);
  % central
  \draw (p31) edge[bend left=10,->] (q3);
  \draw (q3) edge[bend left=10,->] (p23);
  \draw (p41) edge[bend right=10,->] (q4);
  \draw (q4) edge[bend right=10,->] (p24);
  % right
  \draw (p23) edge[bend left=15,->] ($(q2.north west)!.5!(q2.west)$);
  \draw (p24) edge[bend right=15,->] (q2.west);

% round arrows on the...

  % ...left
\draw[->] ($(p11.west)+(2pt,4pt)$) arc (240:105:1.8em);
\draw[<-] ($(p11.east)+(-2pt,4pt)$) arc (-60:75:1.8em);
  % ...right
\draw[->] ($(p22.west)+(2pt,4pt)$) arc (240:105:1.8em);
\draw[<-] ($(p22.east)+(-2pt,4pt)$) arc (-60:75:1.8em);

% huge round arrows from the top node
\draw[->] (p12) edge[out=180,in=145] ($(q1.north west)!.5!(q1.west)$);
\draw[->] (p12) edge[out=0,in=35] ($(q2.north east)!.5!(q2.east)$);

\end{tikzpicture}
\caption{Event graph}
\end{figure}
\end{document}
  • thanks very much, this looks far better (and is much more organised) than my attempt! – Tom Offer May 1 '15 at 11:19
  • @TomOffer You're welcome! :) – Alenanno May 1 '15 at 12:13

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.