# Tikz: drawing dual graph

I am drawing a graph and its dual one in the same plot. I came up with this solution

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{graphs,quotes}
%%\usegdlibrary{layered}

\begin{document}

\tikz  {

\node[draw,circle,thick,fill=black!20] (A) at (0,0)[] {A};
\node[draw,circle,thick,fill=black!20] (B) at (3,0) {B};
\node[draw,circle,thick,fill=black!20] (C) at (6,-2) {C};
\node[draw,circle,thick,fill=black!20] (D) at (0,-4) {D};
\node[draw,circle,thick,fill=black!20] (E) at (3,-4) {E};

\node[draw,circle,thick,fill=green!20] (ABD) at (1.5,-1) {};
\node[draw,circle,thick,fill=green!20] (BDE) at (2,-3) {};
\node[draw,circle,thick,fill=green!20] (out) at (-2,2) {};
\node[draw,circle,thick,fill=green!20] (BCE) at (4.5,-2) {};

\node (BotLeft) at (-2,-6) {};
\node (BotLeft2) at (-1.75,-4.75) {};

%%graph G
\graph {
(A) --["$e_2$ 6",near end] (B);
(A) --["$e_1$ 1",swap] (D);
(D) --["$e_5$ 2"] (B);
(D) --["$e_4$ 1",swap,near start] (E);
(E) --["$e_6$ 2",swap,near end] (B);
(E) --["$e_7$ 5",swap,near end] (C);
(B) --["$e_3$ 5",near start] (C);
};

%%dual graph G*
\graph {
(ABD) --["$e^*_5$ 2",dashed, near end] (BDE);
(ABD) --["$e^*_2$ 6",dashed,bend right=50,swap,near end] (out);
%%(out) --["$e^*_1$ 1",dashed,bend right=50,swap,near end] (ABD);
%%(BDE) --["$e^*_4$ 1",dashed,bend left=160,out=180,in=-90,swap] (out);
(BDE) --["$e^*_6$ 2",dashed,swap] (BCE);
(BCE) --["$e^*_3$ 5",dashed,bend right=100,swap] (out);
};
\draw[dashed] (out) to[bend right=50] node[left]  {$e^*_1\,1$} (ABD);
\draw[dashed] (out) to[out=-120,in=-90,bend right] node[left] {$e^*_7\,5$} (BotLeft) to[bend right=100] (BCE);
\draw[dashed] (out) to[bend right] node[right,near end] {$e^*_4\,1$} (BotLeft2) to[bend right=100] (BDE);
}

\end{document}


I find this an extreme ugly hack. I'm looking for a simpler (less code) and more elegant solution (not involving the "phantom" nodes BotLeft*; using only \graph or only \draw...).

The problem here is making some of those dual edges open up enough to go around the original vertices. I've tried with various bend values and combined that with in/out but that doesn't seem enough: the edge ends up warped on itself almost.

There is already a similar question here but it has been labeled as duplicate without providing the link to the duplicated question; furthermore, they say it's been answered in there, but that only mentions the bending, which I couldn't make work for this problem.

Also, my impression from the pgf manual is that something like this requires a "hack". Alas, I couldn't figured out a simple solution to it. The problem, however, should be common enough to deserve on such solution.

• FYI: the link to the duplicated question will be put at the top of the webpage. – Symbol 1 Jun 8 '17 at 2:27

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

\begin{document}
\centering
\begin{tikzpicture}[
V/.style = {% V as Vortex
draw,circle,thick,fill=#1},
V/.default = black!20
]
\node[V] (A) at (0,0)[] {A};
\node[V] (B) at (3,0) {B};
\node[V] (C) at (6,-2) {C};
\node[V] (D) at (0,-4) {D};
\node[V] (E) at (3,-4) {E};
\begin{scope}[V/.default = green!20]
\node[V] (ABD) at (1.5,-1) {};
\node[V] (BDE) at (2,-3) {};
\node[V] (out) at (-2,2) {};
\node[V] (BCE) at (4.5,-2) {};
\end{scope}

%%graph G
\draw
(A) to ["$e_2$ 6",near end] (B)
(A) to ["$e_1$ 1" '] (D)
(D) to ["$e_5$ 2"] (B)
(D) to ["$e_4$ 1",near start] (E)
(E) to ["$e_6$ 2" ',near end] (B)
(E) to ["$e_7$ 5" ',near end] (C)
(B) to ["$e_3$ 5",near start] (C);
%%dual graph G*
\clip (-4,-6) rectangle + (10.5,9.2);% remove empty spaces caused by looseness option
%\draw (-4,-6) rectangle + (10.5,9.2); % to see clip border
\draw[dashed]
(ABD) to ["$e^*_5$ 2",near end] (BDE)
(ABD) to ["$e^*_2$ 6",bend right=50,swap,near end] (out)
(BDE) to ["$e^*_6$ 2" '] (BCE)
(BCE) to ["$e^*_3$ 5" ',bend right=100] (out)
(out) to ["$e^*_1$ 1" ',bend right=50]  (ABD)
(out) to ["$e^*_7$ 5" ', out=-135,in=-105,looseness=2.7] (BCE)
(out) to ["$e^*_4$ 1"  , out=-135,in=-120,looseness=2.2] (BDE);
\end{tikzpicture}
\end{document}

• Thanks. The clip is a neat added bonus. So just using looseness makes the edges bend smoothly avoiding the other edges. It's function though seems to partially overlap with bend. Another interesting effect is that order seems to matter sometimes: Removing the looseness of e^*_4 (last edge) and swapping that line with that of e^*_7 (with looseness) makes the latter not show the dashed edge. Not helpful in debugging. As a side note, your code has a e^*_6 that is duplicated – MASL Jun 9 '17 at 15:46
• Regarding the graph Vs draw question. I think it could be done using only draw and nodes, but can't it be done just using graph? If not what's the point of using graph? But if it can be done using only graph, wouldn't there be a simpler code using just that? – MASL Jun 9 '17 at 15:49
• @MASL, see edited answer. Now I don't use graph{...};, since I don't see any benefits with it use (with \draw the code is more concise). Label e^*_4 1 is now moved to near end. Duplicated line is removed. Other remarks I don't understand. With looseness is eliminated auxiliary nodes (coordinates). It can be used also at other dashed lines, for example line labeled with e_3 5. Order of codes for lines had not any influence on their appearing. – Zarko Jun 9 '17 at 16:40