如何为图中的每个连通分量赋予简单的标签

如何为图中的每个连通分量赋予简单的标签

我有一个不连续的图,有六个组件。我想在底部为每个组件命名。我想用 $D_1, D_2 . . D_6$ 来表示它们。有人能帮我吗?

 \documentclass{article}
\usepackage{tikz}
\begin{document}
 \begin{figure}
\begin{tikzpicture}
[scale=.8,auto=left,every node/.style={circle,fill=blue!30,linewidth=10mm,inner sep=0pt,minimum size=10pt}]

\node (n1) at (8,0)  {e};
\node (n2) at (0,0)  {e};
\node (n3) at (0,-2)  {fg};
\node (n4) at (8,-2)  {abcdhijk};
\node (n5) at (6,0)  {h};
\node (n6) at (2,0)  {h};
\node (n7) at (2,-2)  {ikj};
\node (n8) at (6,-2)  {abcdefg};
\node (n9) at (0,0)  {d};
\node (n10) at (0,-2)  {abc};
\node (n11) at (3,0)  {d};
\node (n12) at (3,-2)  {efg};
\node (n13) at (4,0)  {d};
\node (n14) at (4,-2)  {hijk};

\foreach \from/\to in {n2/n3,n1/n4,n5/n8,n6/n7,n9/n10,n11/n12,n13/n14}
 \draw (\from) -- (\to);

\end{tikzpicture}
\end{figure}
\end{document}

答案1

就像这样:

\documentclass{article}
\usepackage{tikz}
\begin{document}
    \begin{figure}
        \begin{tikzpicture}[scale=.8,auto=left,graph/.style={circle,fill=blue!30,linewidth=10mm,inner sep=0pt,minimum size=10pt}]
            \begin{scope}[every node/.style=graph]
                \node (n1) at (8,0)  {e};
                \node (n2) at (0,0)  {e};
                \node (n3) at (0,-2)  {fg};
                \node (n4) at (8,-2)  {abcdhijk};
                \node (n5) at (6,0)  {h};
                \node (n6) at (2,0)  {h};
                \node (n7) at (2,-2)  {ikj};
                \node (n8) at (6,-2)  {abcdefg};
                \node (n9) at (0,0)  {d};
                \node (n10) at (0,-2)  {abc};
                \node (n11) at (3,0)  {d};
                \node (n12) at (3,-2)  {efg};
                \node (n13) at (4,0)  {d};
                \node (n14) at (4,-2)  {hijk};
            \end{scope}
            \foreach \from/\to/\number in {n2/n3/1,n1/n4/6,n5/n8/5,n6/n7/2,n9/n10/5,n11/n12/3,n13/n14/4}
            {
                \draw (\from) -- (\to) node[below=0.6cm] {D\number};
            }
        \end{tikzpicture}
    \end{figure}
\end{document}

在此处输入图片描述

请注意,您有重复的节点(n5 和 n8)。

相关内容