3

I have the following code that I created:

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[->]

  \node[label=west:$s$,circle,fill,inner sep=1.5pt] (n0) at (-1,1) {};
  \node[label=west:$e_1$,circle,fill,inner sep=1.5pt] (n3) at (0,2) {};
  \node[label=east:$e_2$,circle,fill,inner sep=1.5pt] (n4) at (2,2) {};
  \node[label=west:$e_3$,circle,fill,inner sep=1.5pt] (n1) at (0,0) {};
  \node[label=east:$e_4$,circle,fill,inner sep=1.5pt] (n2) at (2,0) {};
  \node[label=north:$e_5$,circle,fill,inner sep=1.5pt] (n5) at (1,1) {};
  \node[label=south:$e_6$,circle,fill,inner sep=1.5pt] (n6) at (1,0) {};
  \node[label=west:$e$,circle,fill,inner sep=1.5pt] (n7) at (3,1) {};

\path
(n1) edge [bend right=60] node [swap] {} (n2);

\end{tikzpicture}

\end{document}

enter image description here

I want to create edges, just like the bended ones between all $e_i$ (complete directed graph with edges going both ways) and between $s -> e_i$ and $e_i -> e$.

I could do it manually, but it seems very taxing, especially since the graph could become larger. I would also have to bend each edge in the right way.

Is there some package/magic tikz option that would allow me to create a complete subgraph over $e_i$ and add edges between $s$ to all $e_i$ and between all $e_i$ to $e$?

  • Check out the accepted answer, by Bordaigorl, to this question. – DJP Nov 22 '14 at 6:10
3

Is this what you're trying to accomplish?

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}

\begin{document}

\begin{tikzpicture}[-{Stealth[scale=1.25]},my node style/.style={circle,fill,inner sep=1.5pt}]

  \node[label=west:$s$,my node style]    (n0) at (-1,1) {};
  \node[label=west:$e_1$,my node style]  (n3) at (0,2)  {};
  \node[label=east:$e_2$,my node style]  (n4) at (2,2)  {};
  \node[label=west:$e_3$,my node style]  (n1) at (0,0)  {};
  \node[label=east:$e_4$,my node style]  (n2) at (2,0)  {};
  \node[label=north:$e_5$,my node style] (n5) at (1,1)  {};
  \node[label=south:$e_6$,my node style] (n6) at (1,0)  {};
  \node[label=west:$e$,my node style]    (n7) at (3,1)  {};

  \let\myp\relax
  \foreach \myc in {1,2,4,3,1}
  {
    \ifx\myp\relax
    \else
      \path (n\myp) edge [bend right=50] node [swap] {} (n\myc);
      \path (n\myc) edge [bend right=20] node [swap] {} (n\myp);
    \fi
    \xdef\myp{\myc}
  }
\end{tikzpicture}

\end{document}

enter image description here

It seems that some kind of tweaking is going to be necessary to avoid getting a rat's nest. Here I should an approach that might suit you. (Note I changed your names for the nodes because, frankly, I found your names rather confusing.)

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}

\begin{document}

\begin{tikzpicture}[-{Stealth[scale=1.25]},my node style/.style={circle,fill,inner sep=1.5pt}]

  \node[label=west:$s$,my node style]    (s) at (-1,1) {};
  \node[label=west:$e_1$,my node style]  (e1) at (0,2)  {};
  \node[label=east:$e_2$,my node style]  (e2) at (2,2)  {};
  \node[label=west:$e_3$,my node style]  (e3) at (0,0)  {};
  \node[label=east:$e_4$,my node style]  (e4) at (2,0)  {};
  \node[label=north:$e_5$,my node style] (e5) at (1,1)  {};
  \node[label=south:$e_6$,my node style] (e6) at (1,0)  {};
  \node[label=west:$e$,my node style]    (e) at (3,1)  {};

  \let\myp\relax
  \foreach \myc in {1,2,4,3,1}
  {
    \ifx\myp\relax
    \else
      \path (e\myp) edge [bend right=20] node [swap] {} (e\myc);
      \path (e\myc) edge [bend right=30] node [swap] {} (e\myp);
    \fi
    \xdef\myp{\myc}
  }


  \foreach \myc/\myout/\myin/\mylooseness in {1/120/130/2,
                                              2/135/130/2,   
                                              3/250/250/1.5,   
                                              4/210/250/2,    
                                              5/0/180/0,    
                                              6/230/230/2}
  {
      \path[red] (s) edge [out=\myout,in=\myin,looseness=\mylooseness] node [swap] {} (e\myc);
  }



\end{tikzpicture}

\end{document}

enter image description here

  • Thanks! The second graph is almost what I want, but I also need edges to e_5. and also I wanted pairwise relations, for example between e_1 and e_4, e_3 and e_2. Last, also edges from e_1-e_5 to e. I will try to tweak your code to do that, but if you have insight, would be happy to hear. thanks again. – kloop Nov 22 '14 at 11:32

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.