Tikz:绘制对偶图

Tikz:绘制对偶图

我正在同一图中绘制一个图及其对偶图。我想出了这个解决方案 在此处输入图片描述

\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}

我觉得这是一个极其丑陋的黑客行为。我正在寻找一个更简单(更少代码)和更优雅的解决方案(不涉及“幻影”节点 BotLeft*;仅使用 \graph 或仅使用 \draw...)。

这里的问题是让一些双边缘足够张开以绕过原始顶点。我尝试了各种弯曲值并将其与 in/out 结合,但这似乎还不够:边缘最终几乎扭曲了自身。

已经有一个类似的问题这里但它被标记为重复,没有提供重复问题的链接;此外,他们说它已经在那里,但那只提到了弯曲,我无法解决这个问题。

另外,我从 pgf 手册中得到的印象是,类似这样的事情需要“破解”。唉,我没能想出一个简单的解决方案。然而,这个问题应该很常见,值得采用这样的解决方案。

答案1

![在此处输入图片描述

\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}

相关内容