9

I want to draw this automaton:

enter image description here

But I drew it with a bad way !!

\documentclass{article}
\usepackage{pgf}
\usepackage{tikz}
\usetikzlibrary{arrows,automata}
\usepackage[latin1]{inputenc}
\begin{document}
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2.8cm,semithick]
\node[initial,state] (A) {$1$};
\node[state] (B) [right of=A] {$2$};
\node[state] (C) [right of=B] {$3$};
\node[state] (D) [right of=C] {$4$};
\node[state,accepting] (E) [right of=D] {$5$};
\node[state,accepting] (F) [below of=E] {$6$};
\node[state,accepting] (G) [below of=D] {$7$};
\node[state,accepting] (H) [below of=G] {$8$};
\node[state,accepting] (I) [below of=H] {$9$};
\node[state] (J) [below of=A] {$10$};
\node[state,accepting] (P) [below of=J] {$16$};
\node[state] (K) [below left of=I] {$11$};
\node[state] (L) [right of=K] {$12$};
\node[state,accepting] (M) [right of=L] {$13$};
\node[state,accepting] (N) [below of=L] {$14$};
\node[state,accepting] (O) [below of=M] {$15$};
\node[state,accepting] (Q) [below of=B] {$17$};
\path (A) edge node {X}(B)
          edge node{I} (C)
          edge node{V} (J)
      (B) edge [loop above] node {X}(B)
          edge node{I} (C)
          edge node{V} (J)
          edge node{<>I,<>V} (Q)
      (C) edge node {X}(H)
          edge node{I} (D)
          edge node{V} (G)
          edge node{Autre} (I)
      (D) edge node {I}(E)
          edge node{<>I} (F)
      (J) edge node {I}(K)
          edge node{<>I} (P)
      (K) edge node {I}(L)
          edge node{<>I} (N)
      (L) edge node {I}(M)
          edge node{<>I} (O);
\end{tikzpicture}
\end{document}

enter image description here

  • 2
    you can use edge[bend left] etc. – Leo Liu May 2 '13 at 1:38
  • How can I draw a transition between state 1 and 3 ? – GoldRay May 2 '13 at 1:42
14

You can add bend left or bend right or bend left=<degree> or bend right=<degree> to the edges. Here is an example:

\usetikzlibrary{positioning,automata}
\begin{tikzpicture}[shorten >=1pt,node distance=2cm,on grid]
  \node[state,initial]   (q_0)                {$q_0$};
  \node[state]           (q_1) [right=of q_0] {$q_1$};
  \node[state,accepting] (q_2) [right=of q_1] {$q_2$};
  \path[->] (q_0) edge                node [above] {0} (q_1)
                  edge [loop above]   node         {1} ()
                  edge [bend left=45] node [below] {1} (q_2)
                  edge [bend right]   node [below] {0} (q_2)
            (q_1) edge                node [above] {1} (q_2);
\end{tikzpicture}

Result:

enter image description here

  • 1
    Try this: \texttt{<>} – SaltyEgg May 2 '13 at 1:50
  • 1
    @user29570: Try \path (I) +(<x_offset>, <y_offset>) node[state] (K) {$11$}; – SaltyEgg May 2 '13 at 2:36
  • 1
    @user29570: I'm not sure if this is what you want: Add a line \noindent\hskip -1cm before \begin{tikzpicture}. You can change -1cm to a suitable value. – SaltyEgg May 2 '13 at 2:59
  • 1
    @user29570: Add a line \vskip -1cm before \noindent\hskip -1cm. BTW, if you add \usetikzpackage{positioning}, you can use relative position like this: [below left=5cm of I]. – SaltyEgg May 2 '13 at 3:11
  • 1
    Maybe this works: \hbox{}\vskip -1cm – SaltyEgg May 2 '13 at 3:40
4

quite late, but here is your answer ;)

\begin{tikzpicture}[shorten >=1pt,auto,node distance=2.8cm,semithick]
\node[state,initial] (A) {$1$};
\node[state] (B) [right of=A] {$2$};
\node[state] (C) [right of=B] {$3$};
\node[state] (D) [right of=C] {$4$};
\node[state,accepting] (E) [right of=D] {$5$};
\node[state,accepting] (F) [below of=E] {$6$};
\node[state,accepting] (G) [below of=D] {$7$};
\node[state,accepting] (H) [below of=G] {$8$};
\node[state,accepting] (I) [below of=H] {$9$};
\node[state] (J) [below of=A] {$10$};
\node[state,accepting] (P) [below of=J] {$16$};
\node[state] (K) [below left of=I] {$11$};
\node[state] (L) [right of=K] {$12$};
\node[state,accepting] (M) [right of=L] {$13$};
\node[state,accepting] (N) [below of=L] {$14$};
\node[state,accepting] (O) [below of=M] {$15$};
\node[state,accepting] (Q) [below of=B] {$17$};
\path[->] 
      (A) edge [bend left=45] node {$X$}(B)
          edge [bend left=80] node{$I$} (C)
          edge node{$V$} (J)
      (B) edge [loop above] node {$X$}(B)
          edge [bend left=45] node {$I$} (C)
          edge node {$V$} (J)
          edge node {$<>I,<>V$} (Q)
      (C) edge [bend left=-5] node {$X$} (H)
          edge [bend left=45] node {$I$} (D)
          edge [bend left=15] node {$V$} (G)
          edge [bend left=-25] node {Autre} (I)
      (D) edge [bend left=45] node {$I$}(E)
          edge node {$<>I$} (F)
      (J) edge [bend left=15] node {$I$}(K)
          edge node {$<>I$} (P)
      (K) edge [bend left=45] node {$I$}(L)
          edge node {$<>I$} (N)
      (L) edge [bend left=45] node {$I$}(M)
          edge node{$<>I$} (O);
\end{tikzpicture}

here is the result

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.