I'm trying to make boxes around parts of my tree, but I find no command to do so. I have tried the qtree package, which has the !qframesubtree that can do the job, but only for complete subtrees. What I want to do is to draw one box around the upper part of the tree (including the IP) and another box around the rest of the tree (including the VP).

\ex \Tree [.IP Spec [.I\1 I [.VP Spec [.V\1 V XP ] ] ] ] 

Any tips on how to do this.

I include a simple drawing of the desired result. enter image description here

EDIT: With the comments below I have now solved the problem. This is the code I ended up with:

sn edges/.style={for tree={parent anchor=south, child anchor=north,align=center,base=bottom{}}},
background tree/.style={for tree={text opacity=0.2,draw opacity=0.2,}},
\begin{forest} sn edges,
[IP, tikz={\node [draw, fit=()(Spec)(Ibar)(I)]{};}, s sep=3em,
    [{Spec}, name=Spec]
    [I',name=Ibar, l sep=2em, s sep=6.5em,
        [I, name=I ]        
    [VP, tikz={\node [draw, inner sep=0.03em, fit=()(!1)(!ll)]{};}
            [XP]] ]] ]

enter image description here

2 Answers 2


If you can accept forest instead of qtree, it's easy to do something similar to what you want.

tikz={\node [draw, red, fit=()(!1)(!ll)]{};} is an option which calls TiKZ to draw a node which fits the present node, its first child and last grandchild.

The green square could be also written with tikz={\node [draw, green, fit to tree]{};}

for tree={s sep=5mm, fit=band}
[IP, tikz={\node [draw, red, fit=()(!1)(!ll)]{};}, 
   [I` [I]
       [VP, tikz={\node [draw, green, fit=()(!1)(!ll)]{};}
           [V' [V]

enter image description here


Whilst I myself would recommend using the forest solution above, here's a way to do it in tikz-qtree by using the fit library that comes together with tikz to fit tikz's nodes into a box.




\Tree [.\node(ip){IP}; \node(specip){Spec}; [.\node(ibar){I$'$}; \node(i){I}; [.\node(vp){VP}; \node(specvp){Spec}; [.V$'$ V \node(xp){XP}; ] ] ] ]


EDIT: I've edited the code to address your question in the comment to this answer. Note that it is also possible to use tikzset to tweak the distance between the tree's nodes so as to stop the boxes touching the nodes they aren't meant to be touching.

  • Many thanks! A furhter question. Is there any way to make the VP escape the upper box? Commented Mar 19, 2015 at 9:19
  • @DavidKroik Indeed it is. See the edited answer. Commented Mar 19, 2015 at 9:32
  • @PavelRudnev, I am using your solution - works nicely so far. One question though: Is there an easy way to attach the tree edges to the top of the boxes? Currently, the edges reach inside the boxes. Thanks! Commented Jan 3, 2017 at 14:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .