I have following code –
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows,automata,calc,shapes, positioning}
\begin{document}
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,node distance=3.0cm,thick]
\tikzstyle{every state}=[fill=white,draw=black,text=black,minimum size=45pt]
\node[state] (A) {$A$};
\node[state] (B) [right of=A] {$B$};
\node[state] (C) [right of=B] {$C$};
\path (A) [loop above] edge (A);
\path (A) edge (B)
(B) edge (C)
(A) edge [bend left=45] node [above, xshift=-2mm,yshift=-3.5mm,very near start] {$1$} (B)
(A) edge [bend left=45] (C);
% Hard-coded the token location since i don't know about it.
\fill[black] (0.00,1.75) circle (2pt);
\end{tikzpicture}
\end{document}
This generates an image like this –
However, I would like to add some text to the edges. Thus I want to have my output something like this –
How can I achieve this in the Tikz?
Thanks !
Raj
Best Answer
Every tikz node has 360 anchor points using the notation
nodename.angle
, beingangle
an integer between 0 and 360. Those anchors are placed at the intersection between the node shape and a radius with the given angle. You can use those anchors to set the starting point of the arcs, and also for the labels with$1$
.UPDATE: Also, a small improvement about the dot you place "manually". It is more convenient giving the coordinates of that point in polar coordinates with respect node
A
. The point is located at 9mm at north ofA.north
, so you can specify its coordinates as(A.north) +(90:9.1mm)
. The9.1mm
part is still manually estimated, but making the coordinates relative saves you from recalculate them if you move theA
node.Quoting only the relevant part:
Produces:
Second update
The proper way of adding the token in the edge is to use a
markings
decoration. The syntax is a bit utgly because the decoration has to be added in apostaction
, but using the example provided below you can easily add tokens to any edge in your graph.