Tikz - How to Draw Boxes Around Set of Nodes

\node[draw,dotted] {A};

or

\draw[dotted] (0,0) rectangle (2,2);

Other options would be densely dotted, loosely dotted, dashed, densely dashed, and loosely dashed.

If you want to fit stuff, use the fit-library (example in Plain):

\input tikz
\usetikzlibrary{fit}
\tikzpicture
\foreach \x/\z in {A/1,B/2,C/3,D/4,E/5,F/6,G/7} {
  \node at (\z,0) (\x) {\x};
}
\node[draw,dotted,fit=(A) (B) (C)] {};
\endtikzpicture
\bye

Following Caramdir's suggestion on inner sep, I composed a LaTeX example with some additional tikz libraries which you might be interested in:

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{ matrix,      % For easy node positioning
                 fit,         % For easily fitting nodes inside another one
                 positioning, % For easy node-relative placements
               }
\begin{document}
\begin{tikzpicture}[ % Dims on their own lines for easy tweakage
  myscope/.style={node distance=1em and 0em},
  mymatrix/.style={matrix of nodes, nodes=block,
    column sep=2em,
    row sep=1em},
  block/.style={draw=blue, thick, fill=blue!20, rounded corners,
    minimum width=6em,
    minimum height=2em},
  vhilit/.style={draw=red, thick, dotted,
    inner sep=1em},
  hhilit/.style={draw=black, thick, densely dotted,
    inner xsep=2em,
    inner ysep=.5em},
  line/.style={thick, -latex, shorten >= 2pt}
  ]

  \matrix[mymatrix] (mx) { % Usage of matrix-lib
    & Subanta \\
    Pumlinga  & & Pumlinga \\
    Strilinga & & Strilinga \\
    Napumsaka & & Napumsaka \\
  }; % Now you can refer to nodes as "matrixname-rownumber-columnnumber"

  \begin{scope}[myscope]
    \coordinate[below left=of mx-1-2] (leftBranch); % Usage of positioning-lib
    \coordinate[below right=of mx-1-2] (rightBranch);
  \end{scope}

  \draw[thick] (mx-1-2) |- (leftBranch) -- (rightBranch);

  \foreach \x in {2,3,4} {
    \draw[line] (leftBranch)  |- (mx-\x-1);
    \draw[line] (rightBranch) |- (mx-\x-3);
  }

  \node[vhilit, fit=(mx-2-3) (mx-3-3) (mx-4-3)] {}; % Usage of fit-lib
  \node[hhilit, fit=(mx-4-1) (mx-4-3)] {};

\end{tikzpicture}
\end{document}


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


You can use the fitting library from tikz. Here you have your modified example.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,fit} %use shapes library if you need ellipse
\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);

\node[draw=red, fit=(I) (L)](FIt1) {};
\node[ellipse,draw=green, fit=(J) (L),inner sep=3mm](FIt2) {};

\end{tikzpicture}
\end{center}
\caption{Summary of Linga } \label{linga}
\end{figure}
\end{document}

and the result

alt text

Hope it helps.