3

I have six states in an automata drawing:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{automata}

\begin{document}
\begin{tikzpicture}[node distance=5cm,thick,every state/.style={minimum size=3cm}]
  \node[state,draw=blue,fill=blue!20] (A) {A};
  \node[state,draw=red,fill=red!20] (B) [right of=A] {B};
  \node[state,draw=red,fill=red!20] (E) [below of=B] {E};
  \node[state,draw=blue,fill=blue!20] (C) [right of=B] {C};
  \node[state,draw=green!50!black,fill=green!20] (D) [below of=A] {D};
  \node[state,draw=red,fill=red!20] (F) [below of=C] {F};
  \path[-,violet,line width=1mm]
  (A) edge node [color=black,sloped,above] {G1,G2,G3} (E)
  edge node [color=black,sloped,above] {G1} (B)
  (D) edge node [color=black,sloped,above] {G4} (E)
  (C) edge node [color=black,sloped,above] {G5} (E)
  edge node [color=black,sloped,above] {G5} (F)
  (E) edge node [color=black,sloped,above] {G5} (F)
  (B) edge node [color=black,sloped,above] {G1} (E);
\end{tikzpicture}
\end{document}

which produces this

enter image description here

What I want now is to draw a big arrow, touching all the nodes with a text on it.

This example is amazing but I have no Idea how to modify it in order to pass through the nodes.

I want something like this:

enter image description here

But looking nicer (and with TiKZ, the previous image was done in inkscape)

1
  • 1
    'Looking nicer' is rather vague. Your nicer might be my horribler, for example. Overlaying the text and lines shouldn't be a problem but since you don't want it to look like the image you've posted, what should it look like exactly?
    – cfr
    Apr 27, 2015 at 22:22

1 Answer 1

8

This demonstrates one way to superimpose a path with text curved along it. A wide path is drawn using a thick, translucent line. A text along path decoration is used to add the text after the line is drawn in a postaction. Finally, the path is given opaque edges by drawing two additional paths over the first using thin, edging lines.

\documentclass[tikz,border=5pt]{standalone}
\usetikzlibrary{automata,calc,positioning,decorations.text}

\begin{document}
  \begin{tikzpicture}
    [
      node distance=5cm,
      thick,
      every state/.style={minimum size=3cm},
      every edge/.append style={
        every node/.append style={text=black, sloped, above}
      },
    ]
    \node[state,draw=blue,fill=blue!20] (A) {A};
    \node[state,draw=red,fill=red!20] (B) [right=of A.center] {B};
    \node[state,draw=red,fill=red!20] (E) [below=of B.center] {E};
    \node[state,draw=blue,fill=blue!20] (C) [right=of B.center] {C};
    \node[state,draw=green!50!black,fill=green!20] (D) [below=of A.center] {D};
    \node[state,draw=red,fill=red!20] (F) [below=of C.center] {F};
    \path[-,violet,line width=1mm]
    (A)  edge node  {G1,G2,G3}
    (E)  edge node [below]  {G1} (B)
    (D)  edge node  {G4} (E)
    (C)  edge node  {G5} (E)
         edge node  {G5} (F)
    (E)  edge node  {G5} (F)
    (B)  edge node  {G1} (E);
    \path
    [
      line width=7.5mm,
      draw=violet!25,
      opacity=.75,
    ] ($(B.north)!1/2!(E.south)$) coordinate (c) circle (75mm and 40mm);
    \path
    [
      thick,
      draw=violet,
    ] (c) circle (78.75mm and 43.75mm) circle (71.25mm and 36.25mm)
    ;
    \path
    [
      postaction={
        decorate,
        opacity=1,
        decoration={
          text along path,
          text={|\LARGE\sffamily|Some text here Some text here ||},
          raise=-5pt,
          pre length=200mm,
          text color=black,
          reverse path=true,
          pre=moveto
        }
      }
    ]  (c) circle (75mm and 40mm);
  \end{tikzpicture}
\end{document}

curved text

EDIT

Here's an example somewhat similar to the one you linked in your question. It uses thick arrows with text decorations.

\documentclass[tikz,border=5pt]{standalone}
\usetikzlibrary{automata,calc,positioning,decorations.text,arrows.meta,bending}

\begin{document}
  \begin{tikzpicture}
    [
      node distance=5cm,
      thick,
      every state/.style={minimum size=3cm},
      every edge/.append style={
        every node/.append style={text=black, sloped, above}
      },
      my arrow/.style={line width=7.5mm, draw=violet, {Triangle Cap[reversed,bend]}-{Triangle Cap[bend]}},
    ]
    \node[state,draw=blue,fill=blue!20] (A) {A};
    \node[state,draw=red,fill=red!20] (B) [right=of A.center] {B};
    \node[state,draw=red,fill=red!20] (E) [below=of B.center] {E};
    \node[state,draw=blue,fill=blue!20] (C) [right=of B.center] {C};
    \node[state,draw=green!50!black,fill=green!20] (D) [below=of A.center] {D};
    \node[state,draw=red,fill=red!20] (F) [below=of C.center] {F};
    \path[-,violet,line width=1mm]
    (A)  edge node  {G1,G2,G3}
    (E)  edge node [below]  {G1} (B)
    (D)  edge node  {G4} (E)
    (C)  edge node  {G5} (E)
         edge node  {G5} (F)
    (E)  edge node  {G5} (F)
    (B)  edge node  {G1} (E);
    \path [my arrow]  ($(B.north)!1/2!(E.south)$) coordinate (c) +(75mm,0) arc (0:-90:75mm and 40mm);
    \path [my arrow] (c) +(0,-40mm) arc (270:180:75mm and 40mm);
    \path
    [
      my arrow,
      postaction=decorate,
      decoration={
        text along path,
        text={|\LARGE\sffamily|Some text here Some text here ||},
        text color=white,
        raise=-5pt,
        pre length=10mm,
        pre=moveto
        }
    ] (c) +(-75mm,0) arc (180:90:75mm and 40mm);
    \path
    [
      my arrow,
      postaction=decorate,
      decoration={
        text along path,
        text={|\LARGE\sffamily|More text here More text here ||},
        text color=white,
        raise=-5pt,
        pre length=10mm,
        pre=moveto
        }
    ]  (c) +(0,40mm) arc (90:0:75mm and 40mm);
  \end{tikzpicture}
\end{document}

arrows on automata

2
  • Sorry for my vague definition... but your second version is definitely nicer than my sketch ;-) Apr 28, 2015 at 1:54
  • 1
    @AlejandroDC Glad it helped. It is just that when people say 'nicer', there's the problem that people's tastes differ - sometimes radically ;). Note that the [bend] slows compilation a bit but without it, it looked awful. So I think it is worth it. (And unless you are drawing lots and lots of these, it shouldn't really be noticeable, I wouldn't think.) TikZ uses a short-cut for arrows by default because these are more 'expensive'.
    – cfr
    Apr 28, 2015 at 2:09

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.