答案1
这里是一个起点。一切都是可定制的。进行一些搜索,你会发现很多有趣的东西。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows,automata}
\tikzset{every state/.style={fill=yellow!50}}
\begin{document}
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2.8cm,
semithick]
\node[initial,state] (q0) {$q_0$};
\node[state] (q1) [below right of=q0] {$q_1$};
\node[state,accepting] (q2) [above right of=q1] {$q_2$};
\path (q0) edge [bend left] node {0} (q1)
edge [loop] node[above] {1} (q0)
(q1) edge [bend left] node {1} (q0)
edge node {0} (q2)
(q2) edge [loop] node[above]{0} (q2)
edge node[above] {1} (q0);
\end{tikzpicture}
\end{document}
编辑:引文库
按照 Zarko 的建议,这里有一个使用quotes
库的新版本(更轻量级),它产生完全相同的输出。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows,automata,quotes,positioning}
\tikzset{every state/.style={fill=yellow!50}}
\begin{document}
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,
node distance=2.8cm,semithick]
\node[state,initial] (q0) {$q_0$};
\node[state] (q1) [below right = of q0] {$q_1$};
\node[state,accepting] (q2) [above right = of q1] {$q_2$};
\path (q0) edge [bend left,"0"] (q1)
edge [loop,"1" '] (q0)
(q1) edge [bend left,"1"] (q0)
edge ["0"] (q2)
(q2) edge [loop,"0" '] (q2)
edge ["1" '] (q0);
\end{tikzpicture}
\end{document}