4

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}
Speravir
  • 19,491
GoldRay
  • 543

3 Answers3

8

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

kan
  • 4,545
5

Using xy-pic for automata diagrams

enter image description here

\documentclass{article}
\usepackage[all]{xy}
\begin{document}
\xymatrix{%
*+<2pc>[o][F-]{1} \ar@(ul,ul)[]^>>>{start} \ar@/^0pc/[r]^a \ar@/_1pc/[dr]^b
& *+<2pc>[o][F=]{2} \ar@{}[d]^<<<{return(a)}  \\
& *+<2pc>[o][F=]{3} \ar@{}[]^<<<{return(b)} }
\end{document}
Moriambar
  • 11,466
5

For completeness sake, time for an old school automata package: vaucanson-g! :)

Compile with xelatex:

\documentclass{article}

\usepackage{vaucanson-g}
\usepackage{amsmath}

\begin{document}

\begin{VCPicture}{(0,-2)(2,2)}

\State[1]{(-2,2)}{STATEONE}
\FinalState[2]{(2,2)}{STATETWO}
\FinalState[3]{(0,0)}{STATETHREE}

\Initial{STATEONE}
\FinalR{ne}{STATETWO}{\text{return}(a)}
\FinalR{ne}{STATETHREE}{\text{return}(b)}

\LArcL{STATEONE}{STATETWO}{a}
\LArcR{STATEONE}{STATETHREE}{b}

\end{VCPicture}

\end{document}

The output:

Output

Update, per OP request:

\documentclass{article}

\usepackage{vaucanson-g}

\begin{document}

\begin{VCPicture}{(0,-2)(2,2)}

\State[1]{(-2,2)}{STATEONE}
\FinalState[2]{(2,2)}{STATETWO}
\FinalState[3]{(0,0)}{STATETHREE}

\Initial{STATEONE}

\LArcL{STATEONE}{STATETWO}{a}
\LArcR{STATEONE}{STATETHREE}{b}

\rput(4,2){\LARGE return$(a)$}
\rput(2,0){\LARGE return$(b)$}

\end{VCPicture}

\end{document}

The new output:

New output

Paulo Cereda
  • 44,220
  • Thank you ..Is it possible to remove the arrows on the states 2 and 3? – GoldRay Apr 24 '13 at 18:38
  • 1
    @user29570: It's been a while since I used vaucanson-g for the last time, but since it's PSTricks under the hood, we can use \rput and inject our text in the position we want it to appear, as I did in my update. I'm used to see transducers with the output represented as an arrow, but of course this is a matter of personal taste. :) – Paulo Cereda Apr 25 '13 at 11:14