[Tex/LaTex] draw an ellipse into a Tree picture -tikz package

linguisticstikz-pgftikz-qtreetikz-treestrees

I have draw a tree using tikz package like this

\begin{tikzpicture} 
\tikzstyle{level 1}=[sibling distance=40mm] 
\tikzstyle{level 2}=[sibling distance=20mm] 
\tikzstyle{level 3}=[sibling distance=10mm] 
 \node{S} 
      child{node{N} child{node{mary}} }
      child{node{VP}     
            child{node{V} child{node{brought }}}
            child{node{NP}   child{node{D} child{node{a}}} child{node{N} child{node{cat}}}  }
            child{node{PP}  child{node{IN} child{node{to}}}     child{node{N}  child{node{school}}} }                          }
 ; 
 \end{tikzpicture}

the result of my picture it is like this

enter image description here

Now i want to draw an ellipse an some text in my picture to describe her like this

enter image description here

How i can do that , any answer will be appreciate

Best Answer

Name the nodes and use the fit library:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fit,shapes}

\begin{document}

\begin{tikzpicture}[every fit/.style={ellipse,draw,red,inner sep=-2pt},] 
\tikzstyle{level 1}=[sibling distance=40mm] 
\tikzstyle{level 2}=[sibling distance=20mm] 
\tikzstyle{level 3}=[sibling distance=10mm] 
 \node (S) {S} 
      child{node (n) {N} child{node (mary) {mary}} }
      child{node (VP) {VP}     
            child{node{V} child{node{brought }}}
            child{node (np) {NP}   child{node{D} child{node (a) {a}}} child{node{N} child{node (cat) {cat}}}  }
            child{node{PP}  child{node{IN} child{node{to}}}     child{node{N}  child{node{school}}} }                          }
 ; 

\node[fit=(np) (a) (cat)] {};
\node[fit=(n) (mary)] {};
\node[right=1cm,red] at (S) {S $\rightarrow$ N VP};
\node[right=1cm,red] at (VP) {VP $\rightarrow$ V NP PP};

\end{tikzpicture}

\end{document}

enter image description here