Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question

3 Answers 3

up vote 18 down vote accepted

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

share|improve this answer
    
awesome, thanks for your help. –  Aku Jan 13 '11 at 18:35
\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}

share|improve this answer
    
I guess the question from the OP is how to draw boxes around sets of named nodes, without having to guess the appropriate coordinates. –  Juan A. Navarro Jan 13 '11 at 17:42
    
@juan - you are correct, I would like to draw around set of nodes to take the guess work out. –  Aku Jan 13 '11 at 17:47
    
@Aku: I edited my answer accordingly. –  morbusg Jan 13 '11 at 17:50
2  
You might also want to specify inner sep to change how loosely the rectangle fits around the nodes. –  Caramdir Jan 13 '11 at 18:10

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}`\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,fit}
\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);

%Two nodes fitting your selected ones
\node[draw=red, fit=(I) (L)](FIt1) {};
\node[ellipse,draw=green, fit=(J) (L)](FIt2) {};

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

and the result

alt text

Hope it helps.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.