Take the 2-minute tour ×
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 have to crate a petri net for an homework assignment in university. In Tikz manual, I found a very useful tutorial on creating petri nets using Tikz/PGF. However, the example uses a different style for transitions, different from the one my professor prefers. He uses a style similar to the one on Wikipedia:

http://upload.wikimedia.org/wikipedia/commons/6/6a/Petri_Net_A.jpg

Notice that the transition (t) is represented by a small black bar. However, the example in the Tikz tutorial looks like this:

http://i.stack.imgur.com/tA81g.png

Here, transitions are represented by rectangualar boxes. Does anybody know how I can change the style of the transitions? I reckon that this can be done quite easily but please note that I'm a novice when it comes to Tikz and that I barely understood the source code for the petri net above.

Here is the source code from the Tikz guide: (I narrowed it down somewhat so it only includes the left petri net)

\documentclass{article}
\usepackage[version=0.96]{pgf}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,automata,petri}

\begin{document}

\begin{tikzpicture}[node distance=1.3cm,>=stealth',bend angle=45,auto]

  \tikzstyle{place}=[circle,thick,draw=blue!75,fill=blue!20,minimum size=6mm]
  \tikzstyle{transition}=[rectangle,thick,draw=black!75,
              fill=black!20,minimum size=4mm]

    \node [place,tokens=1] (w1)                                    {};
    \node [place] (c1) [below of=w1]                      {};
    \node [place] (s)  [below of=c1,label=above:$s\le 3$] {};
    \node [place] (c2) [below of=s]                       {};
    \node [place,tokens=1] (w2) [below of=c2]                      {};

    \node [transition] (e1) [left of=c1] {}
      edge [pre,bend left]                  (w1)
      edge [post,bend right]                (s)
      edge [post]                           (c1);

    \node [transition] (e2) [left of=c2] {}
      edge [pre,bend right]                 (w2)
      edge [post,bend left]                 (s)
      edge [post]                           (c2);

    \node [transition] (l1) [right of=c1] {}
      edge [pre]                            (c1)
      edge [pre,bend left]                  (s)
      edge [post,bend right] node[swap] {2} (w1);

    \node [transition] (l2) [right of=c2] {}
      edge [pre]                            (c2)
      edge [pre,bend right]                 (s)
      edge [post,bend left]  node {2}       (w2);
\end{tikzpicture}

\end{document}

Thank you very much for your help!

share|improve this question

2 Answers 2

up vote 5 down vote accepted

You can change the transition style to, for example,

  transition/.style={
    rectangle,
    thick,
    fill=black,
    minimum width=8mm,
    inner ysep=2pt
    }

notice that I changed from the deprecated \tikzstyle to the more appropriate \tikzset syntax.

\documentclass{article}
\usepackage[version=0.96]{pgf}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,automata,petri}

  \tikzset{
  place/.style={
    circle,
    thick,
    draw=blue!75,
    fill=blue!20,
    minimum size=6mm
  },
  transition/.style={
    rectangle,
    thick,
    fill=black,
    minimum width=8mm,
    inner ysep=2pt
    }
  }            

\begin{document}

\begin{tikzpicture}[node distance=1.3cm,>=stealth',bend angle=45,auto]


    \node [place,tokens=1] (w1)                                    {};
    \node [place] (c1) [below of=w1]                      {};
    \node [place] (s)  [below of=c1,label=above:$s\le 3$] {};
    \node [place] (c2) [below of=s]                       {};
    \node [place,tokens=1] (w2) [below of=c2]                      {};

    \node [transition] (e1) [left of=c1] {}
      edge [pre,bend left]                  (w1)
      edge [post,bend right]                (s)
      edge [post]                           (c1);

    \node [transition] (e2) [left of=c2] {}
      edge [pre,bend right]                 (w2)
      edge [post,bend left]                 (s)
      edge [post]                           (c2);

    \node [transition] (l1) [right of=c1] {}
      edge [pre]                            (c1)
      edge [pre,bend left]                  (s)
      edge [post,bend right] node[swap] {2} (w1);

    \node [transition] (l2) [right of=c2] {}
      edge [pre]                            (c2)
      edge [pre,bend right]                 (s)
      edge [post,bend left]  node {2}       (w2);
\end{tikzpicture}

\end{document}

enter image description here

share|improve this answer
    
Terrific answer. Thanks for your help! –  IronMan12 Apr 8 at 18:28

I modified the code a little bit to make it similar than the one that you showed at the beginning. Try it!

\documentclass{article}
\usepackage[version=0.96]{pgf}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,automata,petri}

\tikzset{
place/.style={
circle,
thick,
draw=black,
%fill=blue!20,
minimum size=6mm
  },
  transition/.style={
    rectangle,
    thick,
        draw=black,
    minimum width=8mm,
    inner ysep=2pt
    }
  }     
\begin{document}

\begin{tikzpicture}[node distance=1.5cm,>=stealth',bend angle=45,auto]


    \node [place,tokens=2] (w1) [label=above:$N$]                    {};
        \node [place,inner sep=0pt, minimum size=0pt] (blank) [left of=w1] {};
    \node [place,tokens=2] (c1) [left of=blank, label=above:$H$]     {};

    \node [transition] (e1) [below of=blank, label=right:$s$] {}
      edge [pre]                  (w1)
      edge [pre]    node{2}       (c1);
    \node [place] (d1) [below of=e1, label=below:$N_2H$] {}
      edge [pre]                  (e1);
\end{tikzpicture}

\end{document}
share|improve this answer

Your Answer

 
discard

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.