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 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 -

enter image description here

However, I would like to add some text to the edges. Thus I want to have my output something like this - enter image description here

How can I achieve this in the Tikz?

Thanks ! Raj

share|improve this question
1  
Does setting bend left=25 for the edge from A to B achieve what you're trying to do? –  Jake Dec 11 '12 at 15:26
    
oh yes ! I tried and it worked ! :) Thanks a lot ! –  Raj Dec 11 '12 at 15:28
add comment

2 Answers

up vote 4 down vote accepted

Every tikz node has 360 anchor points using the notation nodename.angle, being angle 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 of A.north, so you can specify its coordinates as (A.north) +(90:9.1mm). The 9.1mm part is still manually estimated, but making the coordinates relative saves you from recalculate them if you move the A node.

Quoting only the relevant part:

  \path (A) [loop above] edge (A);
  \path (A) edge (B) 
        (B) edge  (C) 
        (A.20) edge [bend left=30]  (B)  
        (A.22) node[above] {$1$}
        (A.50) edge [bend left=45] (C)
        (A.52) node[above] {$1$};

  \fill[black] (A.north) +(90:9.1mm) circle  (2pt);

Produces:

Result

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 a postaction, but using the example provided below you can easily add tokens to any edge in your graph.

\documentclass{article}
\usepackage{tikz}
\begin{document}
\usetikzlibrary{arrows,automata,decorations.markings}
\tikzset{ % Use this style and postaction={decorate} to put a token in an edge
  put token/.style={
     decoration={markings, mark=at position 0.5 with {\fill[red] circle(2pt); }},
  },
}

\begin{tikzpicture}[node distance=3.0cm,thick]
  \tikzset{
    every state/.append style={fill=white,draw=black,text=black,minimum size=45pt},
    every edge/.append style={->,>=stealth',shorten >=1pt}
  }

  \node[state]   (A) {$A$};
  \node[state]   (B) [right of=A] {$B$};
  \node[state]   (C) [right of=B] {$C$};

  \path (A) edge[loop above, put token, postaction={decorate}] (A);
  \path (A) edge (B) 
        (B) edge  (C) 
        (A.20) edge [bend left=30]  (B)  
        (A.22) node[above] {$1$}
        (A.50) edge [bend left=45] (C)
        (A.52) node[above] {$1$};
\end{tikzpicture}
\end{document}

Result

share|improve this answer
    
ah this is great ! :) –  Raj Dec 11 '12 at 15:42
    
even the dot improvement looks good... I was going to put something like this - node[midway,above=-7pt] {\tikz\fill circle (3pt);} but somehow it didn't work. –  Raj Dec 11 '12 at 15:51
    
@RajTendulkar I added an example of using decorations.markings to put the token at the correct place in a general way. It looks the right thing to do. –  JLDiaz Dec 11 '12 at 17:37
    
I think its even more clean. :) Thanks ! –  Raj Dec 11 '12 at 17:40
add comment

This is the final 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=30] node [above, xshift=-1mm,yshift=-0.85mm,very near start] {$1$} (B)  
        (A) edge [bend left=50] node [above, xshift=-5mm,yshift=-3.5mm,very near start] {$1$} (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}
share|improve this answer
add comment

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.