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.

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

share|improve this question

1 Answer 1

up vote 12 down vote accepted

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

share|improve this answer
1  
I did exactly the same, I took the liberty to edit your post to add the labels –  Tom Bombadil Jun 10 '12 at 20:22
1  
@TomBombadil: thanks; I was just going to add the texts in red. –  Gonzalo Medina Jun 10 '12 at 20:23
    
+1 thanks to both of u –  Wassim Sboui Jun 10 '12 at 20:24

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.