3

I'm trying to create two transitions between states while using the TiKZ library for automata drawing.

Currently, I have this example code :

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows,automata}
\begin{document}
\begin{tikzpicture}[>=stealth',shorten >=1pt,auto,node distance=4cm]
    \node[state] (A)                {A};
    \node[state] (B) [right of = A] {B};
    \path[->] (A) edge [bend left]  node {x = 0} (B)
              (B) edge [bend right] node {x = 1} (A);
\end{tikzpicture}
\end{document}

Which yields the following result :

My ugly FSM

I'd like to have two arrows between the states instead : one with x = 0, and the second one with x = 1.

How can I do that with TiKZ?

2
  • 1
    Welcome to TeX.SE. And thanks for providing a MWE. It is sometimes difficult to get one from some who have been here for a while, so it is really great to see it from a new user. – Peter Grill Mar 20 '13 at 22:03
  • It's good to know that I made a good first impression. :) – Daniel Kamil Kozar Mar 20 '13 at 22:06
3

Usingbend left for both edges yields:

enter image description here

Notes;

  • The bend left, bend right direction is relative to the direction of the edge. If both edges were from A to B, the bend left, bend right would work. But, in this case since one is from A to B, and the other is from B to A, then both need to bend left to obtain the desired results.

  • Math content should always be in math mode. See changes made in MWE related to the labels for the edges.

Code:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows,automata}
\begin{document}
\begin{tikzpicture}[>=stealth',shorten >=1pt,auto,node distance=4cm]
    \node[state] (A)                {A};
    \node[state] (B) [right of = A] {B};
    \path[->] (A) edge [bend left]  node {$x = 0$} (B)
              (B) edge [bend left] node {$x = 1$} (A);
\end{tikzpicture}
\end{document}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.