3

How would I label the arrows in the following:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{petri}
\tikzset{state/.style={circle,draw=gray,inner sep=0pt,minimum size=7mm,label=center:$#1$,name=#1},
redarrow/.style={->, red, fill=none,>=stealth},bluearrow/.style={->, blue, fill=none,>=stealth},  
redline/.style={-,red,fill=none},blueline/.style={-,blue,fill=none}}

\begin{document}

\begin{tikzpicture}
\node[state=a^{-1}]{};
\node[state=1,right=of a{-1}]{};
\node[state=b,above=of 1]{};
\node[state=a,right=of 1]{};
\node[state=ab^{-1},above=of a]{};
\node[state=aa,right=of a]{};
\node[state=ac,below=of a]{};
\node[state=acc,right=of ac]{};
\node[state=aca,below =of ac]{};
\draw[redarrow](a^{-1})--(1);
\draw[redarrow](1)--(b);
\draw[redarrow](1)--(a);
\draw[redarrow](ab^{-1})--(a);
\draw[redarrow](a)--(aa);
\draw[redarrow](a)--(ac);
\draw[redarrow](ac)--(acc);
\draw[redarrow](ac)--(aca);
\end{tikzpicture}

\end{document}  
4
  • Add node[midway,above] {1a} at the end to see for an example to any \draw
    – percusse
    Aug 10, 2014 at 19:09
  • Could you pls scrrenshot the output please? I get an error in the line "\node[state=1,right=of a]{};" Aug 10, 2014 at 19:11
  • 1
    @AbhimanyuArora Change the second line right=of a to right=of a^{-1}
    – percusse
    Aug 10, 2014 at 19:12
  • @percusse could you please explain this? I do not understand what you mean. Thanks for replying so quickly!
    – ogs
    Aug 10, 2014 at 19:24

1 Answer 1

4

See below with first connection labelled as 1a

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{petri}
\tikzset{state/.style={circle,draw=gray,inner sep=0pt,minimum size=7mm,label=center:$#1$,name=#1},
redarrow/.style={->, red, fill=none,>=stealth},bluearrow/.style={->, blue, fill=none,>=stealth},  
redline/.style={-,red,fill=none},blueline/.style={-,blue,fill=none}}

\begin{document}

\begin{tikzpicture}
\node[state=a^{-1}]{};
\node[state=1,right=of a^{-1}]{};
\node[state=b,above=of 1]{};
\node[state=a,right=of 1]{};
\node[state=ab^{-1},above=of a]{};
\node[state=aa,right=of a]{};
\node[state=ac,below=of a]{};
\node[state=acc,right=of ac]{};
\node[state=aca,below =of ac]{};
\draw[redarrow](a^{-1})--(1) node[midway,above] {1a};
\draw[redarrow](1)--(b);
\draw[redarrow](1)--(a);
\draw[redarrow](ab^{-1})--(a);
\draw[redarrow](a)--(aa);
\draw[redarrow](a)--(ac);
\draw[redarrow](ac)--(acc);
\draw[redarrow](ac)--(aca);
\node[midway,above] {1a};
\end{tikzpicture}

\end{document}  

Simple example to answer your second comment

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{petri}
\tikzset{state/.style={circle,draw=gray,inner sep=0pt,minimum size=7mm,label=center:$#1$,name=#1},
redarrow/.style={->, red, fill=none,>=stealth},bluearrow/.style={->, blue, fill=none,>=stealth},  
redline/.style={-,red,fill=none},blueline/.style={-,blue,fill=none}}

\begin{document}

\begin{tikzpicture}
\node[state] (nodea) {.};
\node[state] (nodeb) [right=of nodea]{.};
\draw[redarrow](nodea)--(nodeb) node[midway,above] {1a};
\end{tikzpicture}

\end{document}  
2
  • If I wanted to draw this again but without labeling nodes just having dots how would I do that?
    – ogs
    Aug 10, 2014 at 19:53
  • I have added a simple example to the original answer Aug 10, 2014 at 20:32

You must log in to answer this question.

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