9
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,%
main node/.style={draw,circle,minimum size=20pt, inner sep =1pt},node   distance=0.5cm]
% the vertices
\node[draw,circle,inner sep=3pt,minimum size=3pt] [label=left:Source] (source)   at (0,-0.9) {};
  \node[main node] (three) at (1.5,0) {E1};
 \node[main node] [above=of three] (a) {D8};
 \node[main node] [above=of a] (two) {D1};
 \node[main node] [below=of three] (four) {N1};
 \node[main node] [below=of four, label=center:RD] (fourteen) {\phantom{0}};
\node[main node] [below=of fourteen] (b) {DO};
\node[main node] [right=of three] (six) {E1};
\node[main node] [above=of six] (five) {D8};
 \node[main node] [above=of five] (g) {D1};
\node[main node] [below=of six] (seven) {N1};
\node[main node][right=of six] (eight) {E1};
 \node[main node] [below=of seven] (fifthteen) {RD};
  \node[main node] [below=of fifthteen] (d) {DO};
  \node[main node] [above=of eight] (nine) {D8};
   \node[main node] [above=of nine] (c) {D1};
   \node[main node] [below=of eight] (ten) {N1};
   \node[main node] [below=of ten] (sixteen) {RD};
 \node[main node] [below=of sixteen] (e) {DO};
\node[main node] [right=of nine] (seventeen) {D8};
  \node[main node] [above=of seventeen] (c) {D1};
\node[main node] [below=of seventeen] (elleven) {E1};
\node[main node] [below=of elleven] (twelwe) {N1};
\node[main node] [below=of twelwe] (thirteen) {RD};
 \node[main node] [below=of thirteen] (f) {DO};
 \node[main node] [right=of c] (h) {D1};
   \node[main node] [below=of h] (i) {D8};
  \node[main node] [below=of i] (j) {E1};
\node[main node] [below=of j] (k) {N1};
 \node[main node] [below=of k] (l) {RD};
 \node[main node] [below=of l] (m) {DO};
      \node[main node] [right=of h] (n) {D1};
   \node[main node] [below=of n] (o) {D8};
  \node[main node] [below=of o] (p) {E1};
\node[main node] [below=of p] (q) {N1};
\node[main node] [below=of q] (r) {RD};
 \node[main node] [below=of r] (s) {DO};
 \node[main node] [right=of n] (t) {D1};
   \node[main node] [below=of t] (u) {D8};
  \node[main node] [below=of u] (v) {E1};
\node[main node] [below=of v] (w) {N1};
\node[main node] [below=of w] (x) {RD};
 \node[main node] [below=of x] (y) {DO};
 % the edges
  \path[every node/.style={font=\sffamily\small}]
 (four) edge [dashed] node {} (seven)
       edge node {} (fifthteen)
           edge [dashed] node {} (d)
(fifthteen) edge [dashed] node {} (sixteen)
                edge [dashed] node {} (ten)
                edge node {} (e)
(e) edge [dashed] node {} (elleven)
        edge [dashed] node {} (seventeen)
        edge [dashed] node {} (twelwe)
        edge node {} (c)
        edge [dashed] node {} (thirteen)
        edge [dashed] node {} (f)
(source) edge [dashed] node {} (two)
            edge [dashed] node {} (three)
            edge node {} (four)
            edge [dashed] node {} (fourteen)
            edge [dashed] node {} (a)
            edge [dashed] node {} (b)
    (c) edge [dashed] node {} (h)
        edge [dashed] node {} (i)
        edge node {} (j)
        edge [dashed] node {} (k)
        edge [dashed] node {} (l)
        edge [dashed] node {} (m)
    (j) edge [dashed] node {} (n)
        edge [dashed] node {} (s)
        edge node {} (o)
        edge [dashed] node {} (p)
        edge [dashed] node {} (q)
        edge [dashed] node {} (r)       
    (o) edge node {} (x)
;
\draw [|-|] (0.6,-6.5) -- (2.3,-6.5);
\draw [-|] (2.3,-6.5) -- (4.0,-6.5);
\draw [-|] (4.0,-6.5) -- (5.7,-6.5);
\draw [-] (5.7,-6.5) -- (7.4,-6.5);
\draw [|-|] (7.4,-6.5) -- (9.1,-6.5);
\node [below] at (1.4,-6.5) {Day 1};
\node [below] at (3.1,-6.5) {Day 2};
\node [below] at (4.8,-6.5) {Day 3};
\node [below] at (6.5,-6.5) {Day 4};
\node [below] at (8.2,-6.5) {Day 5};
\end{tikzpicture}}

The code above gives the following figure. However I would like that the edges are not crossing over the nodes. For example the edge from DO cross over both RD and D1. How do I move the edges such that they do not cross over any of the nodes?

enter image description here

  • Please make your example into a complete minimum WORKING example. – JPi Mar 25 '17 at 19:02
  • \tikzset{to path={(\tikztostart)..controls+(1,0)and($(\tikztotarget)-(1.5,0)$)..(\tikztotarget)}}. – Symbol 1 Mar 25 '17 at 19:29
18

Add the following to your code

\makeatletter
\tikzset{
    to path={
        \pgfextra{
            \tikz@scan@one@point\relax(\tikztostart)
            \pgfmathsetmacro\start@x{\pgf@x}
            \pgfmathsetmacro\start@y{\pgf@y}
            \tikz@scan@one@point\relax(\tikztotarget)
            \pgfmathsetmacro\target@x{\pgf@x}
            \pgfmathsetmacro\target@y{\pgf@y}
            \pgfmathsetmacro\middle@x{(\start@x+\target@x)/2}
            \pgfmathsetmacro\middle@ya{(4*\start@y+\target@y)/5}
            \pgfmathsetmacro\middle@yb{(\start@y+4*\target@y)/5}
        }
        ..controls(\middle@x pt,\middle@ya pt)and(\middle@x pt,\middle@yb pt)..(\tikztotarget)
    }
}

idea

to draw a curve that avoids other nodes, we need two auxiliary points: A and B. It is of course your freedom to decide where should A and B be.

In my code, the x-coordinate of them is the average. The y-coordinates are 1:5 and 4:5 of the difference of the two ends. This is the reason you why can see /2 and 4* and /5.

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.