# Gradient fill for nodes with forest package

With Tikz, I can specify that my tree nodes use a gradient fill by specifying the top and bottom colours, using something like this:

\usepackage{tikz}
\begin{tikzpicture}[every node/.style = {shape=rectangle, rounded corners, draw, align=center, top color=white, bottom color=aubergine!20}]]
\node {$a$};
\end{tikzpicture}


I would like to use a similar fill for the nodes in a diagram I have created with the forest package.

I can use a solid colour by setting the fill option in the before typesetting nodes part of the diagram definition but I cannot see a way to specify a gradient fill:

\begin{forest}
before typesetting nodes={for tree={draw, fill=aubergine!20}},
[A[B]]
\end{forest}


Is it possible?

I don't see any problem using top color and bottom color:

\documentclass[tikz,border=2mm]{standalone}
\usepackage{forest}

\begin{document}
\begin{forest}
before typesetting nodes={for tree={draw, top color=red!20, bottom color=red!80}},
[A[B]]
\end{forest}
\end{document}


• I didn't think to try that, but in hindsight I guess it was slightly obvious. Thanks! – Adam Williams Mar 2 '17 at 12:06
• @AdamWilliams You don't need before typesetting nodes here. Just for tree={...} will do. (This will be slightly quicker.) – cfr Mar 3 '17 at 2:52