[Tex/LaTex] Create an automaton with LaTeX

automatatikz-pgf

I want to create this automaton with LaTeX:

screenshot

The code:

\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2.8cm,
semithick]
\node[initial,state] (A) {$1$} ;
\node[state,accepting] (B) [right of=A] {$2$};
\node[state,accepting] (C) [below of=A] {$3$};

\path (A) edge node  {a} (B)
edge node {b} (C)

\end{tikzpicture}

Best Answer

Are you looking for something like this?

\documentclass{amsart}
\usepackage{tikz}
\usetikzlibrary{automata, positioning}
\begin{document}
\begin{tikzpicture}[node distance=2cm,auto]
\node[state,initial] (q_0) {1};
\node[state, accepting, label = below right:return(a)] (q_1) at (3,0) {2};
\node[state, accepting, label = below right:return(b)] (q_2) at (1.5,-2) {3};

\path[->] (q_0) edge node[swap] {$b$} (q_2);
\path[->, bend left = 30] (q_0) edge node {$a$} (q_1);
\end{tikzpicture}
\end{document}

Here's how the output looks like:

mwe_for_automaton.png

Related Question