这个自动机的边缘标题样式确实很奇特,但我不知道如何使用 tikz 来重现它,如能得到任何帮助我将不胜感激!
我只能使用 tikz 自动机库来绘制如下所示的简单自动机:
\usepackage{tikz}
\usetikzlibrary{automata, arrows.meta, positioning}
% ... codes ...
\begin{tikzpicture} [node distance = 2cm, on grid, auto]
\node (q0) [state, initial, initial text = {}] {$l_0$};
\node (q1) [state, below = of q0] {$l_1$};
\node (q2) [state, below = of q1] {$l_2$};
\path [-stealth, thick]
(q0) edge node {$x = *; true$} (q1)
(q1) edge node {$y = 1; x >= 0$} (q2)
(q2) edge [bend left] node[left] {$!(x>0); x < 0$} (q0)
\end{tikzpicture}
答案1
\documentclass[tikz, border=1cm]{standalone}
\usetikzlibrary{automata, arrows.meta, positioning}
\tikzset{
colorl/.style={rounded corners=5pt, font=\scriptsize, inner xsep=6pt, inner ysep=0pt, text height=7pt, text depth=3pt},
upperl/.style={fill=violet!40, yshift=5.5pt, colorl},
lowerl/.style={fill=teal!40, yshift=-5.5pt, colorl},
}
\begin{document}
\begin{tikzpicture}[node distance=3cm, on grid]
\node[state, initial, initial text={}] (q0) {$l_0$};
\node[state, below=of q0] (q1) {$l_1$};
\node[state, below=of q1] (q2) {$l_2$};
\draw[-stealth, thick]
(q0) edge node[upperl]{$x=*; true$} node[lowerl]{$!(x>0); x < 0$}(q1)
(q1) edge node[upperl]{$x=*; true$} node[lowerl]{$y=1; x >= 0$} (q2)
(q2) edge[bend left=2cm] node[upperl]{$x < 0$} node[lowerl]{$y=1; x >= 0$} (q0);
\end{tikzpicture}
\end{document}