使用 TikZ 的超边图

使用 TikZ 的超边图

我想用 latex 生成附图。它也是一个超边图。你能帮我吗?颜色可以省略。

提前致谢。

在此处输入图片描述

答案1

您应该提供 MWE!无论如何,下面是我的代码。

在此处输入图片描述

\documentclass[tikz,border=5mm]{standalone}
\begin{document}
\begin{tikzpicture}[line width=1.2pt,
n/.style={circle,draw=#1,text=#1,font=\bfseries\sffamily},
arr/.style={-latex,shorten >=1pt,#1}]

\path
(0,0)       node[n=black] (L1) {2} 
+(0:1)      node[n=black] (R1) {1}
++(-90:1.5) node[n=blue] (L2) {1} 
+(0:1)      node[n=blue] (R2) {2}
++(-90:1.5) node[n=red!70!black] (L3) {2} 
+(0:1)      node[n=red!70!black] (R3) {1};

\draw[arr] (L1)--(L2) coordinate[pos=.4](A);
\fill (A) circle(1mm) node[left=1mm]{$X_2$};
\draw[arr] (R1)--(R2) coordinate[pos=.4](B);
\draw[arr] (B)--(L2);
\fill (B) circle(1mm) node[right=1mm]{$X$};

\draw[arr=blue] (L2)--(L3) coordinate[pos=.4] (C);
\fill[blue] (C) circle(1mm) node[left=1mm]{$R_1$};
\draw[arr=blue] (R2)--(R3) coordinate[pos=.4](D);
\draw[arr=blue] (D)--(L3);
\draw[arr=blue] (C)--(R2);
\fill[blue] (D) circle(1mm) node[right=1mm]{$R_2$};

\draw[arr] (L3)--+(-90:.8);
\draw[arr] (R3)--+(-90:.8);
\end{tikzpicture}
\end{document}

答案2

一个练习,使用@Black Mild 的答案作为 OP 的 MWE:

\documentclass[tikz,border=5mm]{standalone}
\usetikzlibrary{arrows.meta,
                chains,
                positioning}

\begin{document}
    \begin{tikzpicture}[
node distance = 12mm and 9mm,
  start chain = A going below,
   dot/.style = {circle, fill=#1, inner sep=2pt, outer sep=0pt},
    cn/.style = {circle, draw=#1, semithick,
                 text=#1, minimum size=1.2em, inner sep=2pt,
                 on chain=A},
every edge/.style = {draw=#1, -{Triangle[angle=60:2pt 3]},semithick, shorten >=1pt}
                        ]
\node[cn=black] {2};                % A-1
\node[cn=blue]  {1};
\node[cn=red!70!black]  {2};        % A-3
%
\draw   (A-1) edge[black] node (d1) [dot=black,label=left:$X_2$] {} (A-2)
        (A-2) edge[blue]  node (d2) [dot=blue, label=left:$R_1$] {} (A-3) 
        (A-3) edge[black] ++ (0,-1)
        ;
%%        
\node[cn=black,
      right=of A-1] {1};            % A-4
\node[cn=blue]      {2};
\node[cn=red!70!black]  {1};        % A-6
%
\draw   (A-4) edge[black] node (d3) [dot=black,label=right:$X_1$] {} (A-5)
        (A-5) edge[blue]  node (d4) [dot=blue, label=right:$R_2$] {} (A-6)
        (A-6) edge[black] ++ (0,-1);
%% cross lines
\draw   (d3) edge (A-2)
        (d2) edge (A-5)
        (d4) edge (A-3);
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容