# Colouring the branches of tikz trees

I want to colour the branches of the following tree:

\documentclass[12pt,a4paper]{article}
\usepackage{tikz-qtree}
\usepackage{tikz-qtree-compat}
\tikzset{every tree node/.style={align=center,anchor=north}}
\usepackage[normalem]{ulem}

\begin{document}

\begin{tikzpicture}
\Tree
[.S
[.DP E
[.NP PRO
[.NP $\lambda_1$
[.NP S
[.S
[.DP    [.D\\the ] [.N\\pictures ]]
[.VP    [.V\\display ]
[.DP [.D\\the ] [.NP [.N\\man ]
[.S   ]
]
]
]
]
]
]
]
]
[.VP [.V ] [.DP ]]
]

\end{tikzpicture}

\end{document}


How can I make certain branches (i.e, the lines of the tree connecting constituents) one colour (and also turn all the node lables the colour of the branches they are on) and other branches another colour? For example, how can I make the far right topmost immediate VP constituent blue, but the other constituents green? Please note, I wish to do this in tikz-qtree and not in forest.

Like so?

\documentclass[12pt,a4paper]{article}
\usepackage{tikz-qtree}
\usepackage{tikz-qtree-compat}
\tikzset{every tree node/.style={align=center,anchor=north}, edge from parent/.style={draw, green}}
\usepackage[normalem]{ulem}

\begin{document}

\begin{tikzpicture}
\Tree
[.S
[.DP E
[.NP PRO
[.NP $\lambda_1$
[.NP S
[.S
[.DP    [.D\\the ] [.N\\pictures ]]
[.VP    [.V\\display ]
[.DP [.D\\the ] [.NP [.N\\man ]
[.S   ]
]
]
]
]
]
]
]
]
\edge[blue]; [.VP [.V ] [.DP ]]
]

\end{tikzpicture}

\end{document}


You can put \edge[...]; before a node and style it any way you want to override the default style (can similarly use \node[...]{...}, see pages 6-8 of the manual).

EDIT: Coloring all text the same color as their parent edge:

\documentclass[12pt,a4paper]{article}
\usepackage{tikz-qtree}
\usepackage{tikz-qtree-compat}
\tikzset{every tree node/.style={align=center, anchor=north, green!50!black}, edge from parent/.style={draw, green}}
\usepackage[normalem]{ulem}

\begin{document}

\begin{tikzpicture}
\Tree
[.S
[.DP E
[.NP PRO
[.NP $\lambda_1$
[.NP S
[.S
[.DP    [.D\\the ] [.N\\pictures ]]
[.VP    [.V\\display ]
[.DP [.D\\the ] [.NP [.N\\man ]
[.S   ]
]
]
]
]
]
]
]
]
\edge [blue]; [.\node [blue] {VP}; [.V ] [.DP ]]
]

\end{tikzpicture}

\end{document}


• Yes, but I wondered whether you can (by means of the same operation) also turn all the node lables the colour of the branches they are on. – user65526 Sep 10 '15 at 11:41
• @user65526 There aren't any node labels in your example. I would think you meant the node contents but you already said that is not what you want. – cfr Sep 10 '15 at 11:46
• I don't know of any way to do that automatically. Of course, you could change the color manually using either \node or {\color{...}...} as @cfr showed in his answer. – JamesNZ Sep 10 '15 at 12:03
• "Node labels" in natural language syntax are often defined as I have used the term. – user65526 Sep 10 '15 at 15:53
• @user65526 'Node label' is not a term I'm familiar with from natural language at all. I can't remember ever hearing or reading this term except in the context of a technical language such as TikZ's. – cfr Sep 10 '15 at 23:22

Like this?

\documentclass[12pt,a4paper]{article}
\usepackage{tikz-qtree}
\usepackage{tikz-qtree-compat}
\tikzset{every tree node/.style={align=center,anchor=north}}

\begin{document}

\begin{tikzpicture}[text=green!50!black]
\Tree
[.S
[.DP E
[.NP PRO
[.NP $\lambda_1$
[.NP S
[.S
[.DP    [.D\\the ] [.N\\pictures ]]
[.VP    [.V\\display ]
[.DP [.D\\the ] [.NP [.N\\man ]
[.S   ]
]
]
]
]
]
]
]
]
[.{\color{blue}VP} [.V ] [.DP ]]
]

\end{tikzpicture}

\end{document}

• No. The branches (the lines), not the nodes. – user65526 Sep 10 '15 at 10:55
• @user65526 Your question makes that clear now but it did not do so at the time I answered it. – cfr Sep 10 '15 at 11:44
• It did specifically refer to the branches,. – user65526 Sep 10 '15 at 15:53
• @user65526 You also talked about the constituent VP. And branch is ambiguous: I tend to think of a branch as not only including the nodes, but primarily consisting of the nodes which are its constituents. Is the branch of a tree just the woody bits? If a branch comes off, I take that to include the leaves, fruit, nuts etc. on the branch. Perhaps in linguistics, 'branch' means just the bare twig, but I'm not a linguist. – cfr Sep 10 '15 at 23:19