2

two questions: first one: 1-how do i make the line going from q2 to q6 go around q5 and not throw q4 and q5? i tried [Bend left = 120] and other numbers but i won't go around it what matter i put as a number.

the second one is: 2- how do i make the arrow from q1 to q4 two separate arrows and not allowing them to share the arrow?

This is my code:

\documentclass{article}

 \usepackage{tikz}

\usetikzlibrary{automata,positioning}
  \begin{document}

 \begin{tikzpicture}[shorten >=1pt,node distance=2cm,on grid,auto] 
 \node[state,initial] (q_0)   {$q_0$}; 
 \node[state,accepting] (q_1) [ right=of q_0] {$q_1$}; 
 \node[state] (q_2) [right=of q_1] {$q_2$}; 
 \node[state] (q_3) [ below=of q_0] {$q_3$}; 
 \node[state] (q_4) [ below=of q_1] {$q_4$}; 
 \node[state] (q_5) [ below=of q_2] {$q_5$}; 
 \node[state] (q_6) [ below=of q_3] {$q_6$}; 
 \path[->] 
 (q_0) edge  node {a} (q_1)
 edge  node {c} (q_3)
 edge  node {b} (q_4)
 (q_1) edge  node  {c} (q_2)
 edge  node {a} (q_4)
 edge [loop above] node {b} ()
 (q_2)edge  node {a} (q_4) 
 edge  node {a} (q_4)
 edge  [bend left] node {b} (q_6)
 edge [loop above] node {c} ()
 (q_3) edge  node  {b} (q_6)
 edge  node {a} (q_1)
 edge [loop left] node {c} ()
 (q_4) edge  node  {c} (q_5)
 edge  node {a} (q_1)
 edge [loop left] node {b} ()
 (q_5) edge  node  {b} (q_6)
 edge  node {a} (q_2)
 edge [loop right] node {c} ()
 (q_6) 
 edge [loop left] node {a,b,c} ();

 \end{tikzpicture}

 \end{document}  

this is my drawing

3

You can use the parameters in, out and looseness (in combination with eventual re-arrangements of the nodes) to avoid crossing edges. Your second problem can be solved by bending the edges, see bend left=15.

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{automata,positioning}

\begin{document}

\begin{tikzpicture}[shorten >=1pt,node distance=2cm,on grid,auto] 
\node[state,initial] (q_0)   {$q_0$}; 
\node[state,accepting] (q_1) [ right=of q_0] {$q_1$}; 
\node[state] (q_2) [right=of q_1] {$q_2$}; 
\node[state] (q_3) [ below=of q_0] {$q_3$}; 
\node[state] (q_4) [ below=of q_1] {$q_4$}; 
\node[state] (q_5) [ below=of q_2] {$q_5$}; 
\node[state] (q_6) [ below=of q_4] {$q_6$}; 
\path[->] 
(q_0) edge node {a} (q_1)
      edge node {c} (q_3)
      edge node {b} (q_4)
(q_1) edge node  {c} (q_2)
      edge [bend left=15] node {a} (q_4)
      edge [loop above] node {b} ()
(q_2) edge node {a} (q_4) 
      edge node {a} (q_4)
      edge [out=0, in=315] node {b} (q_6)
      edge [loop above] node {c} ()
(q_3) edge node {b} (q_6)
      edge [out=160, looseness=3] node {a} (q_1)
      edge [loop below] node {c} ()
(q_4) edge node {c} (q_5)
      edge [bend left=15] node {a} (q_1)
      edge [loop left] node {b} ()
(q_5) edge node {b} (q_6)
      edge node {a} (q_2)
      edge [loop below] node {c} ()
(q_6) edge [loop left] node {a,b,c} ();
\end{tikzpicture}

\end{document}  

For sure, the result could be further improved.

Graph of the automaton without crossing edges

3

enter image description here

\documentclass[border=0.5cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{automata,positioning}

\begin{document}

\begin{tikzpicture}[%
    shorten >=1pt,
    node distance=2cm,
    on grid,
    auto] 
\node[state, initial] (q_0)   {$q_0$}; 
\node[state, accepting] (q_1) [ right=of q_0] {$q_1$}; 
\node[state] (q_2) [right=of q_1] {$q_2$}; 
\node[state] (q_3) [ below=of q_0] {$q_3$}; 
\node[state] (q_4) [ below=of q_1] {$q_4$}; 
\node[state] (q_5) [ below=of q_2] {$q_5$}; 
\node[state] (q_6) [ below=of q_3] {$q_6$}; 
\path[->] 
(q_0) edge node {a} (q_1)
      edge node {c} (q_3)
      edge node[left, near end] {b} (q_4)
(q_1) edge node {c} (q_2)
      edge [bend left=10] node {a} (q_4)
      edge [loop above] node {b} ()
(q_2) edge node {a} (q_4) 
      edge [bend left, out=120, in=90, looseness=1.5] node {b} (q_6)
      edge [loop above] node {c} ()
(q_3) edge node  {b} (q_6)
      edge node[left, near end] {a} (q_1)
      edge [loop left] node {c} ()
(q_4) edge node  {c} (q_5)
      edge [bend left=10] node {a} (q_1)
      edge [loop left] node {b} ()
(q_5) edge node  {b} (q_6)
      edge node {a} (q_2)
      edge [loop right] node {c} ()
(q_6) edge [loop left] node {a,b,c} ();
\end{tikzpicture}

\end{document}
  • In the original question and in your proposal, it is not obvious, which transition from either q0 to q4 or q3 to q1 the input characters a and b belong to. Maybe you can shift them a bit further. – Matthias Nov 22 '17 at 16:20
  • Yes, you are right. I was struggling with that early. Let me try to rearrange it to see if it looks better. – Cragfelt Nov 22 '17 at 16:25
  • By the way, this is why I decided to draw the edge from q3 to q1 around q0 although this looks a bit strange and was not requested by the author of the question. – Matthias Nov 22 '17 at 16:42
  • @Matthias Yes. And that was a nice change you made. I decided to keep the OP's layout, and because I do not handle this kind of plots very good. – Cragfelt Nov 22 '17 at 19:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.