0

I have the following code:

\begin{tikzpicture} [shorten >=1pt, node distance=4cm, auto]
    \node [state, initial]   (00)                 {$(0, 0)$};
    \node [state]            (10) [right = of 00] {$(1, 0)$};
    \node [state]            (20) [right = of 10] {$(2, 0)$};
    \node [state]            (01) [above = of 00] {$(0, 1)$};
    \node [state]            (11) [right = of 01] {$(1, 1)$};
    \node [state, accepting] (21) [right = of 11] {$(2, 1)$};

    \path [->]
        (00) edge              node {a, b} (21)
        (10) edge              node {a}    (01)
        (11) edge [bend right] node {b}    (10)
        (10) edge [bend right] node {b}    (11)
        (20) edge              node {a}    (11)
        (20) edge [bend right] node {b}    (21)
        (01) edge              node {a, b} (20)
        (11) edge              node {a}    (00)
        (21) edge              node {a}    (10)
        (21) edge [bend right] node {b}    (20);
\end{tikzpicture}

which results in this drawing: automata

Now how do I ensure that the labels are clearly readable without changing the position of the nodes?

6
  • You should play with xshift and/or yshift.
    – projetmbc
    Commented Apr 30, 2023 at 22:32
  • @projetmbc Where would I place these attributes?
    – mtxcactus
    Commented Apr 30, 2023 at 22:37
  • For example, you can try (00) edge node[yshift=-22pt] {a, b} (21) .
    – projetmbc
    Commented Apr 30, 2023 at 22:46
  • Well, where do you want to have the labels? You can use the pos key or the predefined near start (pos = .25) and near end (pos = .75) keys to change the position along the arrow. You can swap the position of the label to the other side. And lastly, yes, you can shift the position of the label directly. You can also use sloped which rotates the label such that it follows the direction of the arrow. Commented Apr 30, 2023 at 22:59
  • @Qrrbrbirlbel That was helpful, thanks!
    – mtxcactus
    Commented May 1, 2023 at 2:23

1 Answer 1

3

With pos and sloped I was now able to get it to look more appealing. But I'm sure you could make it look even more visually pleasing.

\begin{tikzpicture} [shorten >=1pt, node distance=4cm, auto]
    \node [state, initial]   (00)                 {$(0, 0)$};
    \node [state]            (10) [right = of 00] {$(1, 0)$};
    \node [state]            (20) [right = of 10] {$(2, 0)$};
    \node [state]            (01) [above = of 00] {$(0, 1)$};
    \node [state]            (11) [right = of 01] {$(1, 1)$};
    \node [state, accepting] (21) [right = of 11] {$(2, 1)$};

    \path [->]
        (00) edge [pos=.15, sloped]    node {a, b} (21)
        (10) edge [pos=.15, sloped]    node {a}    (01)
        (11) edge [bend right]         node {b}    (10)
        (10) edge [bend right]         node {b}    (11)
        (20) edge [near start, sloped] node {a}    (11)
        (20) edge [bend right]         node {b}    (21)
        (01) edge [pos=.15, sloped]    node {a, b} (20)
        (11) edge [pos=.15, sloped]    node {a}    (00)
        (21) edge [near start, sloped] node {a}    (10)
        (21) edge [bend right]         node {b}    (20);
\end{tikzpicture}

An even better looking automata

You must log in to answer this question.

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