I need a whole bunch of images and someone advised me to use Tikz and it seems like it can probably do exactly what I want, however I haven't been able to find some things and I feel like I've been hacking code together in a poor way. I made an example of what I want in paint:

It's basically a diagram with different types of nodes, text on the ends of edges, different types of arrows, including some with a box in the middle that may or may not have text in them, and text labels near the nodes.

What I have so far is:



\begin{tikzpicture}[narray/.style={circle,fill=white,draw},node distance=3cm,
                norm/.style={circle,fill=black,draw,minimum size=0.2cm}]

  \node[narray] (q1) {\tikz\draw[black, fill=black] (0,0) circle (.7ex);} ;
  \node[norm] (p1) [right of=q1] {};

    (q1) edge [->,>=latex',thick] node[above] {A} (p1);

which makes

I feel like using the label to draw the inner circle is the wrong way to do it and I don't know how to get the text there and make the other kinds of arrows that I need. Can someone point me in the right direction?

  • 3
    Take a look at second tutorial in pgfmanual. It explain Petri nets. You have an example here
    – Ignasi
    Commented Jul 11, 2014 at 16:11

1 Answer 1


You're on the right track; however, some improvements can be made to your code; most importantly, nesting tikzpictures is not always the best choice; in fact, in the case at hand, it's not necessary at all.

Here's one possibility using the petri library:



  node distance=3cm,
    minimum size=0.2cm
  >= latex

\node[place,tokens=1,label={80:$n$}] (p1) {} ;
\node[norm,below right=of p1] (q1) {};
\node[place,tokens=1,above right=of q1,label={80:$m$}] (p2) {} ;

    (p1) -- 
    node[pos=0.15,above] {$[2..3]$}
    node[pos=0.85,above] {$[1..2]$}
    (p1) -- 
    node[pos=0.05,below=6pt] {$[4]$} 
    node[midway,draw,fill=white] {$t$}
    mark=at position 0.15 with {\arrow{>}},
    mark=at position 0.9 with {\arrow{<}}
    (p2) -- 


enter image description here


Here I will give some comments about the issued mentioned explicitly in the question.

  1. To approach having different types of \nodes, the recommendation is to define styles (as you were already doing). Notice that the petri library offers you some predefined useful styles (I used place with tokens) .The automata library could also be useful for other kind of diagrams.

  2. To have text in different locations along an edge you can use

    node[pos=<value>,<position>] {text} 

    along the path, as I did in my example. Read the manual to see other possible useful options such as near end, near start, etc. This same construct allows you to place a "box" (a drawn node) along the edge, with or without text.

  3. To have text near the nodes, you can use the label key (again, refer to the manual) or the powerful quotes library (the later requires version 3.0).

  4. To have some arrow tips (or other kinf of decorations) along edges, TikZ offers you a range of decorations; in particular, here I used the decorations.markings library to place to arrow tips at different locations along one of the paths.

  • That's helped a lot, I definitely have a place to start now. I'm wondering though if it's possible to replace the petri net places with something that is a dot with a circle around it, rather than a circle with a dot in it. In short I want less white space. Commented Jul 12, 2014 at 12:37
  • @user1834446 yes, what you suggests is possible, but it's much easier to change the style for tokens, using something like every token/.append style={minimum size=8pt}; let me know if this is enough or if you wat to define a new style. By the way, if you consider my answer solved your proble, don't forget that you can mark it as accepted by clicking the checkmark to its left. In case of doubt, see How do you accept an answer?. Commented Jul 12, 2014 at 16:41

You must log in to answer this question.

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