6

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}

subtree-red

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?

jII
  • 497
Timm
  • 899

1 Answers1

3

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}

enter image description here

Timm
  • 899