7

I'm trying to build a curved edge from s to a named x and a curved edge from s to b named y.

Beside the problem to >>curve<< them properly i want to give them a background like in this question or in this picture picture.

\documentclass[a4paper,10pt]{article}
\usepackage{tikz}
\usetikzlibrary{automata,positioning,arrows,matrix,backgrounds}
\begin{document}
\begin{tikzpicture} [->,>=stealth',shorten >=1pt,auto,node distance=2.5cm,thick,main node/.style={circle,fill=gray!25,draw,font=\sffamily\Large\bfseries}]

    \node[main node] (1)                    {$s$};
    \node[main node] (2) [below of=1]       {a};
    \node[main node] (3) [ right of=2]      {b};
    \node[main node] (4) [below of=2]       {$t$};

    \path[every node/.style={font=\sffamily\small}]
    (2)     edge [bend left=50]     node    {$r^{-1}$}  (3)
    (3) edge [bend left=50,dashed]  node    {$r$}       (2);

    \draw (1)       .. controls +(1, -1)    and +(-1, 1) .. (2) node[midway,above left] {$x$};
    \draw (1) [dashed]  .. controls (1, 2)  and (2,0) ..        (3) node[midway,right]      {$y$};

    % \draw background here ???!

\end{tikzpicture}
\end{document}

i tried many things like in the linked question but can't get a good solution. any advice?

in the end it should like like in this picture:

![][3]

Frank
  • 501
  • What exactly means "properly" in your "to >>curve<< them properly"? Can you please give an objective description of what you want to achieve? – Gonzalo Medina Jul 16 '14 at 17:48
  • the path (edge) should be curved like a sinus function to indicate that there could be more than 1 node between the s node and its destination. – Frank Jul 16 '14 at 18:01

1 Answers1

12

Edit: answer rewritten

After seeing the intended results:

  1. For the "curved" lines, I defined a wavy style which uses snake decoration
  2. For the background grey markings, use a pgfonlayer and redraw those lines with a big line width.

 

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,arrows,backgrounds,decorations.pathmorphing}

\tikzset{
  wavy/.style = {
     decorate,
     decoration = {snake, amplitude=1.5mm, segment length=8mm}
  },
  main node/.style={circle,fill=gray!25,draw,font=\sffamily\Large\bfseries}
}

\begin{document}
\begin{tikzpicture} [->,>=stealth',shorten >=1pt,auto,
    node distance=2.5cm,thick]

    \node[main node] (1)                    {$s$};
    \node[main node] (2) [below of=1]       {a};
    \node[main node] (3) [right of=2]       {b};
    \node[main node] (4) [below of=2]       {$t$};

    \path[every node/.style={font=\sffamily\small}]
    (2) edge [bend left=50]         node    {$r^{-1}$}  (3)
    (3) edge [bend left=50,dashed]  node    {$r$}       (2);

    \path (1)  edge[out=250, in=110, wavy]
               node[inner sep=2mm, above left] {$x$}
          (2);

    \path (1) edge[out=0, in=80, wavy, dashed]
              node[inner sep=2mm, above right]   {$y$}
          (3);

    % \draw background here ???!
    \begin{pgfonlayer}{background}
     \begin{scope}[line width=2mm, black!30, >=, line cap=round,
      shorten >=1mm, shorten <=1mm]
        \path (1)  edge[out=250, in=110, wavy]         (2);
        \path (1) edge[out=0, in=80, wavy, black!20]   (3);
      \end{scope}
    \end{pgfonlayer}
\end{tikzpicture}
\end{document}

Result:

Result

JLDiaz
  • 55,732