我想用 LaTeX 创建这个自动机:
代码:
\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}
答案1
您正在寻找这样的东西吗?
\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}
输出如下所示:
答案2
为了完整起见,是时候使用老式自动机包了:vaucanson-g
!:)
编译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}
输出:
根据 OP 请求进行更新:
\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}
新的输出:
答案3
使用xy-pic用于自动机图
\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}