# How to change the color of subtrees in tikz-qtree?

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:

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

\tikz{
\Tree
[.A
[.B D ]
[.\node[text=red]{C};
\edge[draw=red];\node[text=red]{E};
\edge[draw=red];\node[text=red]{F}; ]
]
}

\end{document}


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?

• 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
• 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:

\documentclass{standalone}
\usepackage{forest}
\begin{document}

\forestset{
sn edges/.style={for tree={parent anchor=south, child anchor=north}},
red subtree/.style={for tree={text=red},for descendants={edge=red}}}
\begin{forest}
sn edges
[A
[B [D]]
[C,red subtree
[E]
[F]]
]
\end{forest}

\end{document}