[Tex/LaTex] How to unite several nodes in one big node using Tikz

nodestikz-trees

I have to implement the Gomory-Hu-Algorithms which requires the reunion of several nodes to one node like it is shown here:

enter image description here

My code is quite simple since the example I want to implement is quite easy and only consists of a graph and a tree that is expanded in each iteration:

\begin{tikzpicture}[auto, node distance=3cm, every loop/.style={},
thick,main node/.style={circle,fill=green!50,draw,font=\sffamily\Large\bfseries},
path/.style={circle, inner sep=2pt,fill=red!50, draw,font=\sffamily\Large\bfseries}]
\tikzstyle{edge_style} = [draw=orange, line width=2, ultra thick]

\node[main node] (b) {a,b,c,d,e};
\node[main node] (a) [below left = 1cm of b] {a};
\node[main node] (c) [right = 1.5cm of b] {c};
\node[main node] (f) [below  = 2cm of b] {f};
\node[main node](e)  [right = 1.5cm of f] {e};
\node[main node](d)  [below right = 1cm of c] {d};
\end{tikzpicture}

As you see till now I am only able to give names like a,b,c,d to a node but what I want is to get a node including nodes with names a,b,c,d.

Best Answer

If all nodes you want to group are close, fit library which defines fit nodes can help you.

I don't understand the relation between the figure and your code, but following code produces the desired figure using a fit node.

\documentclass[border=2mm,tikz]{standalone}
\usetikzlibrary{positioning, fit, shapes.geometric}

\begin{document}
\begin{tikzpicture}[auto, every loop/.style={},
thick,
main node/.style={circle,fill=green!50,draw,font=\sffamily\Large\bfseries},
path/.style={circle, inner sep=2pt,fill=red!50, draw,font=\sffamily\Large\bfseries},
edge_style/.style={draw=orange, line width=2, ultra thick}]

\node[main node] (1) {1};
\node[main node, below= 1mm of 1] (2) {2};
\node[main node, below left= -1mm and 3mm of 1] (0) {0};
\node[main node, below right=-1mm and 3mm of 1] (4) {4};

\node[ellipse, draw=red, fit=(0) (1) (2) (4), inner sep=-1mm] (all) {};

\node[main node, red, fill=gray, above right=5mm and 2cm of all] (3) {3};
\node[main node, blue, fill=gray, below right=5mm and 2cm of all] (5) {5};

\draw (all) -- node [above] {4} (3);
\draw[dashed] (all) -- node[below] {2} (5) -- node[right] {6} (3);
\end{tikzpicture}
\end{document}

enter image description here

Related Question