[Tex/LaTex] Tikz – How to Draw Boxes Around Set of Nodes

node-connectionsnodestikz-pgf

How to draw the boxes as shown in the attached image? I could only manage to draw the chart but could not highlight the desired node / nodes with a rectangle box. Preferably dotted. I could not draw dotted in MS paint.

alt text

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{figure}[!htb]
\begin{center}
\begin{tikzpicture}
[auto,
 block/.style ={rectangle, draw=blue, thick, fill=blue!20, text width=5em,align=center, rounded corners, minimum height=2em},
 block1/.style ={rectangle, draw=blue, thick, fill=blue!20, text width=5em,align=center, rounded corners, minimum height=2em},
 line/.style ={draw, thick, -latex',shorten >=2pt},
 cloud/.style ={draw=red, thick, ellipse,fill=red!20,
 minimum height=1em}]
\draw (2.5,-2) node[block] (C) {Subanta};
\path (0,-3) node[block] (G){ Pumlinga}
      (0,-4) node[block] (H){ Strilinga}
      (0,-5) node[block] (I){ Napumsaka}
      (5,-3) node[block] (J){ Pumlinga}
      (5,-4) node[block] (K){ Strilinga}
      (5,-5) node[block] (L){ Napumsaka};
\draw (C.south) -- ++(0,-0.25) coordinate (linga);
\draw (linga) -- ++(-1,0) coordinate (ling);
\draw[-latex] (ling) |- (G.east);
\draw[-latex] (ling) |- (H.east);
\draw[-latex] (ling) |- (I.east);
\draw (linga) -- ++(1,0) coordinate (hling);
\draw[-latex] (hling) |- (J.west);
\draw[-latex] (hling) |- (K.west);
\draw[-latex] (hling) |- (L.west);
\end{tikzpicture}
\end{center}
\caption{Summary of Linga } \label{linga}
\end{figure}
\end{document}

Thanks for your help.

Best Answer

With the help of the »calc« library you can get it right.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}
  \begin{tikzpicture}[%
    auto,
    block/.style={
      rectangle,
      draw=blue,
      thick,
      fill=blue!20,
      text width=5em,
      align=center,
      rounded corners,
      minimum height=2em
    },
    block1/.style={
      rectangle,
      draw=blue,
      thick,
      fill=blue!20,
      text width=5em,
      align=center,
      rounded corners,
      minimum height=2em
    },
    line/.style={
      draw,thick,
      -latex',
      shorten >=2pt
    },
    cloud/.style={
      draw=red,
      thick,
      ellipse,
      fill=red!20,
      minimum height=1em
    }
  ]
    \draw (2.5,-2) node[block] (C) {Subanta};
    \path (0,-3) node[block] (G) {Pumlinga}
          (0,-4) node[block] (H) {Strilinga}
          (0,-5) node[block] (I) {Napumsaka}
          (5,-3) node[block] (J) {Pumlinga}
          (5,-4) node[block] (K) {Strilinga}
          (5,-5) node[block] (L) {Napumsaka};
    \draw (C.south) -- ++(0,-0.25) coordinate (linga);
    \draw (linga) -- ++(-1,0) coordinate (ling);
    \draw[-latex] (ling) |- (G.east);
    \draw[-latex] (ling) |- (H.east);
    \draw[-latex] (ling) |- (I.east);
    \draw (linga) -- ++(1,0) coordinate (hling);
    \draw[-latex] (hling) |- (J.west);
    \draw[-latex] (hling) |- (K.west);
    \draw[-latex] (hling) |- (L.west);
    \draw[red,thick,dotted] ($(J.north west)+(-0.3,0.6)$)  rectangle ($(L.south east)+(0.3,-0.6)$);
    \draw[thick,dotted]     ($(I.north west)+(-0.5,0.15)$) rectangle ($(L.south east)+(0.5,-0.15)$);
  \end{tikzpicture}
\end{document}

enter image description here