Tikz 图,其中节点是存储顶点的袋子

Tikz 图,其中节点是存储顶点的袋子

我正在尝试绘制一个略有不同的图,其中节点是存储顶点集合的袋子。

数字

我希望得到帮助。

\documentclass[border=3pt]{standalone}
\usepackage[upright]{fourier}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{scopes}
\usetikzlibrary{arrows}
\usetikzlibrary{shapes}
\usepackage{amsmath,xparse}
\usetikzlibrary{calc}

\begin{document}

\begin{tikzpicture}[scale = 1.3]
    \tikzset{roundnode/.style = {thick, draw = black, fill = black, outer sep = 1.5, circle, minimum size = 2pt, scale = 0.75}}

%%%%%%%%% Nodes %%%%%%%%% 
    \node[roundnode = black] (A) at (9, 11){};
    \node[roundnode = black] (B) at (9, 10){};
    \node[roundnode = black] (C) at (7, 9){};
    \node[roundnode = black] (D) at (8.4, 9){};
    \node[roundnode = black] (E) at (9.6, 9){};
    \node[roundnode = black] (F) at (11, 9){};
    
    
    \tikzset{roundnode/.style = {thick, draw = white, fill = white, outer sep = 1.5, circle, minimum size = 2pt, scale = 1}}
    
    \draw[very thick] (9.25, 11) node{$v$};
    \draw[very thick] (9.25, 10) node{$u$};
%%%%%%%%% Edges %%%%%%%%%
    \draw[black, very thick] (A) to (B);
    \draw[very thick] (9.68, 10.5) node{$1$};
    \draw[very thick] (7, 8.5) node{$2$};
    \draw[very thick] (8.4, 8.5) node{$2$};
    \draw[very thick] (9.6, 8.5) node{$2$};
    \draw[very thick] (11, 8.5) node{$2$};
    
    
    \draw[dashed] (9, 10.5) ellipse (0.46 and 0.9);
    \draw[dashed] (T) (7, 9) circle (0.3);
    \draw[dashed] (8.4, 9) circle (0.3);
    \draw[dashed] (9.6, 9) circle (0.3);
    \draw[dashed] (11, 9) circle (0.3);
\end{tikzpicture}
\end{document}

答案1

这是您图片的复制品,我不知道您的代码是否试图复制相同的图形。我建议在这里pic为树分解中的“特殊”节点(我认为您称之为包)制作一个。其余的是绘制节点和边。

像这样:

\documentclass[border=2mm,tikz]{standalone}
\usetikzlibrary{calc}

% COLORS
\definecolor{colorA}{HTML}{573AA8}
\definecolor{colorB}{HTML}{9F110F}
\definecolor{colorC}{HTML}{576B23}
\definecolor{colorD}{HTML}{74624A}
\definecolor{colorE}{HTML}{2C8BAB}
\definecolor{colorF}{HTML}{3A8781}
\definecolor{colorG}{HTML}{8631B3}
\definecolor{colorH}{HTML}{BD7B47}

\tikzset
{% STYLES
  lnode/.style={circle,draw=black,fill=white,minimum size=1cm,text=#1},
  pics/rnode/.style n args={3}{%
    code={%
      \fill[white] ({3-cos(15)},0) circle ({sin(15)});
      \draw[fill=white] ({3-cos(15)},{sin(15)}) -- ({cos(15)},{sin(15)}) arc (15:345:1) -- ({3-cos(15)},{-sin(15)});
      \node (-0) at (0,0) {};
      \node (-1) at  (60:0.4) {\textcolor{color#1}{#1}};
      \node (-2) at (180:0.4) {\textcolor{color#2}{#2}};
      \node (-3) at (300:0.4) {\textcolor{color#3}{#3}};
    }},
  my edge/.style={bend right=0.7cm}
}

\begin{document}
\begin{tikzpicture}[line cap=round,line join=round,thick]
% LEFT GRAPH
\node[cyan] at (0,4) {Graph $G$};
% edges
\draw (-2,-2) rectangle (2,2);
\draw (0,-2) -- (0,2) -- (-2,0) -- (0,-2) -- (2,0) -- (0,2);
% nodes
\node[lnode=colorA] at (-2, 2) {A};
\node[lnode=colorB] at ( 0, 2) {B};
\node[lnode=colorC] at (-2, 0) {C};
\node[lnode=colorD] at (-2,-2) {D};
\node[lnode=colorE] at ( 0,-2) {E};
\node[lnode=colorF] at ( 2, 2) {F};
\node[lnode=colorG] at ( 2, 0) {G};
\node[lnode=colorH] at ( 2,-2) {H};
% RIGHT GRAPH
\begin{scope}[xshift=10cm]
\node[cyan] at (0,4) {Tree decomposition $(T,X)$};
% nodes
\pic             (L)  at (-1.5,0)          {rnode={B}{C}{E}};
\pic[rotate=-60] (TL) at ($(L-0)+(120:3)$) {rnode={B}{A}{C}};
\pic[rotate= 60] (BL) at ($(L-0)+(240:3)$) {rnode={C}{D}{E}};
\pic[rotate=180] (R)  at ($(L-0)+  (0:3)$) {rnode={E}{G}{B}};
\pic[rotate=240] (TR) at ($(R-0)+ (60:3)$) {rnode={G}{F}{B}};
\pic[rotate=120] (BR) at ($(R-0)+(-60:3)$) {rnode={E}{H}{G}};
% edges
\path[colorB] (TL-1) edge[my edge] (L-1) (L-1) edge[my edge] (R-3) (R-3) edge[my edge] (TR-3);
\path[colorC] (BL-1) edge[my edge] (L-2) (L-2) edge[my edge] (TL-3);
\path[colorE] (BR-1) edge[my edge] (R-1) (R-1) edge[my edge] (L-3) (L-3) edge[my edge] (BL-3);
\path[colorG] (TR-1) edge[my edge] (R-2) (R-2) edge[my edge] (BR-3);
\end{scope}
\end{tikzpicture}
\end{document}

其结果为: 在此处输入图片描述

相关内容