# How to give simple label to each connected component of graph

I have a disconnected graph, with six components. I would like to give some name at the bottom for each component. I would like to represent them with $D_1, D_2 . . .D_6$. Can some one help me out.

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

• You can do \node[label={below:\tiny$D_1$}] (n1) at (8,0) {e};. or \foreach \x in {1,2,...,14}{ \node[font=\tiny,inner sep=0pt,anchor=south] at (n\x.south) {$D_{\x}$}; }. Also linewidth= should be line width.
– user11232
Mar 27, 2014 at 15:01

Like so:

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


Note that you have duplicate nodes (n5 and n8).