2

I have following automaton in Tikz:

enter image description here

Is it possible to do a transition similar to this one?

enter image description here

Here's my code:

\begin{tikzpicture}[>=stealth,node distance=2.7cm,auto]
    \node[state,initial,accepting]  (I)                      {$I$};
    \node[state]                    (p) [above right of = I] {$p$};
    \node[state]                    (q) [right of = p]       {$q$};
    \node[state]                    (r) [below right of = I] {$r$};
    \node[state,accepting]          (F) [below right of = q] {$F$};

    \path[->]
        (I) edge                    node {a}     (p)
            edge                    node {b}     (r)
        (p) edge                    node {b}     (q)
            edge [swap, bend right] node {abc}   (F)
        (q) edge [bend left]        node {aabc}  (F)
            edge [swap, bend right] node {c}     (F)
        (r) edge                    node {aabc}  (F)
            edge [swap, bend right] node {c}     (F);   
\end{tikzpicture}
Saraph
  • 121

2 Answers2

4

Like this:

enter image description here

This is simple. Nodes in automaton are as other nodes in tikzpictures, so you can draw lines between them as you wish. In this case with help |- , yshift and -| between nodes I, r and F:

\documentclass[border=3mm,tikz]{standalone}
\usetikzlibrary{automata}

\begin{document}
\begin{tikzpicture}[>=stealth,node distance=2.7cm,auto]
    \node[state,initial,accepting]  (I)                      {$I$};
    \node[state]                    (p) [above right of = I] {$p$};
    \node[state]                    (q) [right of = p]       {$q$};
    \node[state]                    (r) [below right of = I] {$r$};
    \node[state,accepting]          (F) [below right of = q] {$F$};

    \path[->]
        (I) edge                    node {a} (p)
            edge                    node {b}     (r)
        (p) edge                    node {b}     (q)
            edge [swap, bend right] node {abc}   (F)
        (q) edge [bend left]        node {aabc}  (F)
            edge [swap, bend right] node {c}     (F)
        (r) edge                    node {aabc}  (F)
            edge [swap, bend right] node {c}     (F);
\draw[red,thick,->] (I) |- ([yshift=-5mm] r.south) -| (F);% <-- added
\end{tikzpicture}
    \end{document}
Zarko
  • 296,517
0

Zarko's solution is fine is good but I prefried a solution that automatically calculates the correct placement this solution use fit library

\documentclass[border=3mm,tikz]{standalone}
\usetikzlibrary{automata}

\usetikzlibrary{fit}

\begin{document}
\begin{tikzpicture}[>=stealth,node distance=2.7cm,auto]
    \node[state,initial,accepting]  (I)                      {$I$};
    \node[state]                    (p) [above right of = I] {$p$};
    \node[state]                    (q) [right of = p]       {$q$};
    \node[state]                    (r) [below right of = I] {$r$};
    \node[state,accepting]          (F) [below right of = q] {$F$};

    \path[->]
        (I) edge                    node {a} (p)
            edge                    node {b}     (r)
        (p) edge                    node {b}     (q)
            edge [swap, bend right] node {abc}   (F)
        (q) edge [bend left]        node {aabc}  (F)
            edge [swap, bend right] node {c}     (F)
        (r) edge                    node {aabc}  (F)
            edge [swap, bend right] node {c}     (F);


\node[fit=(p) (r) (q) (F) (I)](all){};
\draw[red] (F) |-(all.south) -| (I);
\end{tikzpicture}
    \end{document}

enter image description here

rpapa
  • 12,350