1

I want to draw an automata in TikZ, and I have the following code segment:

\usepackage{tikz}
\usetikzlibrary{automata,arrows}
\begin{document}

\begin{tikzpicture}[>=stealth',shorten >=1pt,auto,node distance=5 cm, scale = 1, transform shape]

\node[initial,state] (B)                                    {$B$};
\node[state]         (AB) [below of=B]                       {$A,B$};
\node[state]         (ABD) [right of=AB]                    {$A,B,D$};
\node[state,accepting]         (BC) [right of=B]                       {$B,C$};
\node[state,accepting]         (ABCD) [right of=BC]                       {$A,B,C,D$};

\path[->] (B) edge [above]  node [align=center]  {$a$} (BC)
      (B) edge [left]      node [align=center]  {$b$} (AB)
      (AB) edge [left]      node [align=center] {$a$} (BC)
      (AB) edge [above]     node [align=center] {$b$} (ABD)
      (BC) edge [loop above] node [align=center] {$a$} (BC)
      (BC) edge [above]      node [align=center] {$b$} (ABCD)
      (ABD) edge [right]     node [align=center] {$a$} (BC)
      (ABD) edge [loop below] node [align=center] {$b$} (ABD)
      (ABCD) edge [below]       node [align=center] {$a$} (BC)
      (ABCD) edge [loop above]  node [align=center] {$b$} (ABCD);

\end{tikzpicture}
\end{document}

Now, I have two problems with the output of this one, first of all at the initial state it has the arrow and additionally it writes start, how can I remove that start text? Secondly, As can be seen I have parallel edges, like:

 (BC) edge [above]      node [align=center] {$b$} (ABCD)
 (ABCD) edge [below]       node [align=center] {$a$} (BC)

But when they are drawn it looks like one thick line, how can I give some space between them so that it is clear that I have parallel connection?

3

To get rid of the default text for the start node, start, add the option initial text=. You can bend edges a bit so that they become visible as separate lines; e.g., add bend left=10.

You don't have to add align=center, since this is the default. You also don't have to say on which side of the edge to put the label. If you don't like the default, just add the swap-option to the node, as e.g. in (B) edge node[swap] {$a$} (BC).

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{automata,arrows}
\begin{document}

\begin{tikzpicture}%
   [>=stealth',shorten >=1pt,auto,node distance=5 cm,
    scale = 1, transform shape]

\node[initial,state,initial text=] (B)                 {$B$};
\node[state]                       (AB)   [below of=B] {$A,B$};
\node[state]                       (ABD)  [right of=AB]{$A,B,D$};
\node[state,accepting]             (BC)   [right of=B] {$B,C$};
\node[state,accepting]             (ABCD) [right of=BC]{$A,B,C,D$};

\path[->]
  (B)    edge                node {$a$} (BC)
  (B)    edge                node {$b$} (AB)
  (AB)   edge                node {$a$} (BC)
  (AB)   edge                node {$b$} (ABD)
  (BC)   edge [loop above]   node {$a$} (BC)
  (BC)   edge [bend left=10] node {$b$} (ABCD)
  (ABD)  edge                node {$a$} (BC)
  (ABD)  edge [loop below]   node {$b$} (ABD)
  (ABCD) edge [bend left=10] node {$a$} (BC)
  (ABCD) edge [loop above]   node {$b$} (ABCD)
;
\end{tikzpicture}
\end{document}

enter image description here

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.