# TikZ newbie issues when drawing a somewhat complex diagram

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:

\documentclass{article}
\usepackage{tikz}

\usetikzlibrary{arrows,automata}

\begin{document}
\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] {};

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


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?

-
Welcome to TeX.SX! –  Nicola Talbot Jul 11 '14 at 15:51
Take a look at second tutorial in pgfmanual. It explain Petri nets. You have an example here –  Ignasi Jul 11 '14 at 16:11

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:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows,petri,positioning,decorations.markings}

\begin{document}

\begin{tikzpicture}[
node distance=3cm,
norm/.style={
circle,
fill=black,
draw,
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) {} ;

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

\end{document}


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. –  user1834446 Jul 12 '14 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?. –  Gonzalo Medina Jul 12 '14 at 16:41