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 draw several trees and now I want to place them in a figure ( side by side or one below the other )

 \documentclass{report}

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

 \begin{document}
 %First picture
 \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(des){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}}} } }
   ; 


  \end{tikzpicture}
   %Second picture
  \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 (VP) {VP}     
        child{node{V} child{node(des){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}}} } ;


  \end{tikzpicture}
  %Third picture
 \begin{tikzpicture}[every fit/.style={ellipse,draw,red,inner sep=-2pt},] 

 \node(V){V}
     child{node(des){brought }};

\end{tikzpicture}


  %fourth picture
 \begin{tikzpicture}[every fit/.style={ellipse,draw,red,inner sep=-2pt},] 

  \node (np){NP}
         child{node{D} child{node{a}} }
        child{node{N} child{node{a}} };


 \end{tikzpicture}

 % ..... the other picture
 \end{document}

So i want to make something like this :

enter image description here

share|improve this question
add comment

2 Answers

up vote 7 down vote accepted

If you're drawing linguistic trees, you really should use the tikz-qtree package. Not only is the input syntax much easier, it also spaces nodes automatically for you. As for positioning, you can use \scopes for the bigger pieces, or even simple \hspaces to arrange the pieces:

\documentclass{article}
\usepackage{tikz-qtree}
\begin{document}

\begin{tikzpicture}
\Tree [.S 
        [.NP [.N Mary ]]
        [.VP [.V brought ] 
             [.NP [.D a ] [.N cat ]]
        ]
      ]
\begin{scope}[xshift=6cm]
\Tree [.VP [.V brought ] 
             [.NP [.D a ] [.N cat ]]
        ]
\end{scope}
\begin{scope}[xshift=9cm]
\Tree [.NP [.D a ] [.N cat ]]
\end{scope}
\begin{scope}[xshift=6cm,yshift=-4cm]
\Tree [.N cat ]
\hspace{1.25cm}
\Tree [.D a ]
\hspace{1.25cm}
\Tree [.N Mary ]
\hspace{1.25cm}
\Tree [.V brought ] 
\end{scope}
\end{tikzpicture}
\end{document}

output of code

share|improve this answer
    
Good advice... But where is the big white arrow? ;-) –  Paul Gaborit Jul 4 '12 at 6:40
    
@PolGab to do that i added \begin{scope}[xshift=4cm] \draw[<-,very thick,red] (-0.9,-2) -- (-1.4,-2); \end{scope} –  Wassim Sboui Jul 4 '12 at 8:00
add comment

Howdy you could use relative positioning which basically allows you to say i want node X y away form Y:

 \documentclass{report}

 \usepackage{tikz}
 \usetikzlibrary{fit,shapes, positioning}

 \begin{document}

 \begin{tikzpicture}[every fit/.style={ellipse,draw,red,inner sep=-2pt}, every node/.append style={font=\tiny}] 
 \tikzstyle{level 1}=[sibling distance=20mm] 
 \tikzstyle{level 2}=[sibling distance=14mm] 
 \tikzstyle{level 3}=[sibling distance=10mm] 
 \node  (S) at (0,0) {S} 
  child{node (n) {N} child{node (mary) {mary}} }
  child{node (VP) {VP}     
        child{node{V} child{node(des){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 (VP)  [right= 5cm of S]{VP}     
        child{node{V} child{node(des){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 (np) [right= 4cm of VP]{NP}
         child{node{D} child{node{a}} }
        child{node{N} child{node{a}} };

 \node(V) [below= 7cm of VP]{V}
     child{node(des){brought }};

 \end{tikzpicture}

 \end{document}

See also the tikz/pgf guide for more information on relative positioning systems. The above example will spread over page boundaries. You can play around with text size and sibling distances until your are satisfied.

Update Altought i don´t like the idea to much i´d like to tell you that one could put all those trees into one single tree and tell tikz not to draw the first level (or to draw it white as shown below).

 \documentclass{report}

 \usepackage{tikz}
 \usetikzlibrary{fit,shapes, positioning}

 \begin{document}

 \begin{tikzpicture}[every fit/.style={ellipse,draw,red,inner sep=-2pt}, every node/.append style={font=\tiny}] 
\tikzstyle{level 1}=[sibling distance=37mm] 
\tikzstyle{level 2}=[sibling distance=25mm] 
\tikzstyle{level 3}=[sibling distance=15mm] 
\tikzstyle{level 4}=[sibling distance=10mm] 

\node  (S) at (0,0) {}[edge from parent/.style={draw,white,thick},level distance=1mm]
child{node{a}
          child[edge from parent/.style={draw,red,thick},level distance=20mm]{node{D} child{node{a}} }
         child[edge from parent/.style={draw,red,thick},level distance=20mm]{node{N} child{node{a}} }}
child{node{PP}
        child[edge from parent/.style={draw,red,thick},level distance=20mm]{node (np) {NP}   child{node{D} child{node (a) {a}}} child{node{N} child{node (cat) {cat}}}  }
        child[edge from parent/.style={draw,red,thick},level distance=20mm]{node{PP}  child{node{IN} child{node{to}}}     child{node{N}  child{node{school}}} } }
        %  
child{node{S}
        child[edge from parent/.style={draw,red,thick},level distance=20mm]{node (n) {N} child{node (mary) {mary}} }
        child[edge from parent/.style={draw,red,thick},level distance=20mm]{node (VP) {VP}%
          child{node{V} child{node(des){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}}} }} 
}


        ;

 \end{tikzpicture}

 \end{document}

The reason why i don´t like this one should be quite clear: we must explicitly tell tikz how we want the subsequent levels to look like since in a tree options given in a higher level will be passed on until the end of the tree.

share|improve this answer
add comment

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.