Is there an elegant way to color subtrees in tikz-qtree, without going through each of the respective nodes and edges by hand?

The following code example shows the ugly way:


    [.B D ]
        \edge[draw=red];\node[text=red]{F}; ]   



Instead I would like to fix the color of a subtree just in one place, for example at its root node (hence at 'C' in the code example). Any suggestions?

  • 1
    I don't have tikz-qtree installed, but can you use a \begin{scope}...\end{scope} within the tree? – Turion Aug 28 '14 at 17:18
  • 1
    Do you mean \tikzset{every level 1 node/.style={text=red}}? – user11232 Aug 29 '14 at 0:37
  • @Turion: no, the scope environment is not to be used inside tikz-qtree. – Timm Aug 29 '14 at 21:48
  • @Harish: no, this only colors B and C, but not the subtree under C. – Timm Aug 29 '14 at 21:53

There is a fairly simple way to color subtrees using the forest package, which has a similar syntax, but is more flexible than tikz-qtree. Here is an MWE:


    sn edges/.style={for tree={parent anchor=south, child anchor=north}},
    red subtree/.style={for tree={text=red},for descendants={edge=red}}}
sn edges
    [B [D]]
    [C,red subtree


enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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