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.

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

1 Answer 1

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}  
share|improve this answer
    
Perfect thankyou! –  ogs Aug 10 at 19:34
    
If I wanted to draw this again but without labeling nodes just having dots how would I do that? –  ogs Aug 10 at 19:53
    
I have added a simple example to the original answer –  Abhimanyu Arora Aug 10 at 20:32

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.