5

I am trying to draw a finite-state automaton using the automata package in TikZ and am having trouble getting an edge to "clear" the other states (that is, not run into them). Having read this answer, I used bend for the edge from q1 to q8; while that edge "clears" q5 and q6, when I tried the same for the backedge from q7 to q2, it didn't work. I also tried in and out from this answer to no avail.

It seems any combination of bend, in, and out parameters that I try still causes that edge to run into q3 and q4. I know I'm missing something, but what? The documentation on the automata package is a bit thin in this regard.

Here's my current MWE:

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{tikz}
\usetikzlibrary{automata,arrows,topaths}

\let\oldepsilon\epsilon
\renewcommand{\epsilon}{\varepsilon}

\begin{document}

\begin{tikzpicture}[>=stealth',node distance=1.5cm,semithick,auto]
    \node                   (l)                             {$\cdots$};
    \node[state]            (q1)    [right of=l]            {$1$};
    \node[state]            (q2)    [right of=q1]           {$2$};
    \node[state]            (q3)    [above right of=q2]     {$3$};
    \node[state]            (q4)    [right of=q3]           {$4$};
    \node[state]            (q5)    [below right of=q2]     {$5$};
    \node[state]            (q6)    [right of=q5]           {$6$};
    \node[state]            (q7)    [below right of=q4]     {$7$};
    \node[state]            (q8)    [right of=q7]           {$8$};
    \node                   (r)     [right of=q8]           {$\cdots$};

    \path[->]   (l)     edge                        node        {}              (q1)
                (q1)    edge                        node        {$\epsilon$}    (q2)
                        edge [bend right=60]        node[swap]  {$\epsilon$}    (q8)
                (q2)    edge                        node        {$\epsilon$}    (q3)
                        edge                        node        {$\epsilon$}    (q5)
                (q3)    edge                        node        {a}             (q4)
                (q4)    edge                        node        {$\epsilon$}    (q7)
                (q5)    edge                        node        {b}             (q6)
                (q6)    edge                        node        {$\epsilon$}    (q7)
                (q7)    edge                        node        {$\epsilon$}    (q8)
                        edge [in=90,out=90,above]   node        {$\epsilon$}    (q2)
                (q8)    edge                        node        {}              (r);
\end{tikzpicture}

\end{document}

MWE Compiled

2
  • 1
    Add distance=2cm, to the edge options.
    – percusse
    Jan 21, 2013 at 2:30
  • Setting looseness=1.5 edge options will also work
    – hpesoj626
    Jan 21, 2013 at 2:34

1 Answer 1

3

Thanks to percusse's comment, I found that adding the distance option to the edge did the trick, adjusting the in and out values to get it just right:

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{tikz}
\usetikzlibrary{automata,arrows,topaths}

\let\oldepsilon\epsilon
\renewcommand{\epsilon}{\varepsilon}

\begin{document}

\begin{tikzpicture}[>=stealth',node distance=1.5cm,semithick,auto]
    \node                   (l)                             {$\cdots$};
    \node[state]            (q1)    [right of=l]            {$1$};
    \node[state]            (q2)    [right of=q1]           {$2$};
    \node[state]            (q3)    [above right of=q2]     {$3$};
    \node[state]            (q4)    [right of=q3]           {$4$};
    \node[state]            (q5)    [below right of=q2]     {$5$};
    \node[state]            (q6)    [right of=q5]           {$6$};
    \node[state]            (q7)    [below right of=q4]     {$7$};
    \node[state]            (q8)    [right of=q7]           {$8$};
    \node                   (r)     [right of=q8]           {$\cdots$};

    \path[->]   (l)     edge                                    node        {}              (q1)
                (q1)    edge                                    node        {$\epsilon$}    (q2)
                        edge [bend right=60]                    node[swap]  {$\epsilon$}    (q8)
                (q2)    edge                                    node        {$\epsilon$}    (q3)
                        edge                                    node        {$\epsilon$}    (q5)
                (q3)    edge                                    node        {a}             (q4)
                (q4)    edge                                    node        {$\epsilon$}    (q7)
                (q5)    edge                                    node        {b}             (q6)
                (q6)    edge                                    node        {$\epsilon$}    (q7)
                (q7)    edge                                    node        {$\epsilon$}    (q8)
                        edge [in=120,out=60,above,distance=2cm] node        {$\epsilon$}    (q2)
                (q8)    edge                                    node        {}              (r);
\end{tikzpicture}

\end{document}

Compiled Solution

2
  • You can retain the in=90,out=90 option. Looks better that way imho.
    – hpesoj626
    Jan 21, 2013 at 2:35
  • @hpesoj626 I guess we disagree on the aesthetics, then. The new in and out values I've chosen work well for my purposes. Jan 21, 2013 at 2:39

You must log in to answer this question.

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