如何在 tikz 中创建完整图表?

如何在 tikz 中创建完整图表?

我有以下我创建的代码:

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

在此处输入图片描述

我想创造边缘,就像全部 $e_i$(具有双向边的完全有向图)并且介于$s -> e_i$和之间$e_i -> e$

我可以手动完成,但这似乎很费力,尤其是当图形变得更大时。我还必须以正确的方式弯曲每条边。

是否有一些包/魔术 tikz 选项可以让我在 上创建一个完整的子图并在到 所有之间以及 到 所有 之间添加$e_i$边?$s$$e_i$$e_i$$e$

答案1

这就是您想要实现的目标吗?

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

在此处输入图片描述

似乎需要进行某种调整以避免陷入困境。这里我应该介绍一种可能适合您的方法。(请注意,我更改了节点的名称,因为坦率地说,我发现您的名称相当令人困惑。)

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

在此处输入图片描述

相关内容