7

I'm trying to draw an automata in LaTeX with TikZ, but I don't know how to make a long transition between two states. I need a sized label to be placed on it.

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{automata,positioning}
\begin{document}
\begin{tikzpicture}[shorten >=1pt,node distance=2cm,on grid,auto] 

   \node[state,initial] (s_0)   {Start 1}; 
   \node[state] (s_1) [right=of s_0] {Start 2}; 
   \node[state] (s_2) [right=of s_1] {Start 3};



    \path[->] 
    (s_0) edge [bend left] node {Path not long enough for text} (s_1);

\end{tikzpicture}
\end{document}

Gives this result:

enter image description here

Anyone here who could help me?

2
  • Welcome to TeX.sx! Your post was migrated here from another Stack Exchange site. Please register on this site, too, and make sure that both accounts are associated with each other (by using the same OpenID), otherwise you won't be able to comment on or accept answers or edit your question. Apr 18, 2013 at 14:30
  • 1
    In your case, you could simply increase the node distance: \node[state, right=5cm of s_0] (s_1) {Start 2}; and/or reduce the width of the node on the path: \path[->] (s_0) edge [bend left] node[align=center, text width=5cm] {Path not long enough for text} (s_1); Apr 18, 2013 at 15:42

1 Answer 1

8

Choose your option.

Code

\documentclass[tikz]{standalone}
\usetikzlibrary{automata,positioning}
\begin{document}
\begin{tikzpicture}[shorten >=1pt,node distance=2cm,on grid,auto] 
  \node[state,initial] (s_0)   {Start 1}; 
  \node[state] (s_1) [right=of s_0] {Start 2}; 
  \node[state] (s_2) [right=of s_1] {Start 3};

  \path[->] (s_0) edge [bend left] node[text width=1.5cm,
                                        align=center
                                       ] {Path not long enough for text} (s_1);
\end{tikzpicture}

\begin{tikzpicture}[shorten >=1pt,node distance=2cm,on grid,auto] 
  \node[state,initial] (s_0)   {Start 1}; 
  \node[state] (s_1) [right=4cm of s_0] {Start 2};% or [node distance=4cm, right=of s_0]
  \node[state] (s_2) [right=of s_1] {Start 3};

  \path[->] (s_0) edge [bend left] node {Path not long enough for text} (s_1);
\end{tikzpicture}
\end{document}

Output

enter image description here

enter image description here

1
  • 1
    the second option only works because you hard coded 4cm. That will not work with text that is not that wide. Is there a generic solution that adjusts the distance between nodes to fit the text on a path? May 3, 2014 at 15:19

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.