0

TextThe edge caption style of this automaton is really fancy, yet I can't figure out how to use tikz to reproduce it, any help would be greatly appreciated!

I could only use tikz automata library to draw trival automatons like below:

\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}
2
  • Welcome to TeX.SE! Edge caption? Do you mean edge labels or edge quotes?
    – Zarko
    Dec 8, 2022 at 14:56
  • Edge label seems to better fit, thanks!
    – GreenieQwQ
    Dec 8, 2022 at 16:26

1 Answer 1

4
\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}

Automata with colored double labels

1
  • Exactly! Much obliged!
    – GreenieQwQ
    Dec 8, 2022 at 16:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .