Mindmap creates connection line composed of the parent/child colors. Is it possible to apply such effect on normal parent/child trees to connect the parent and child nodes with a gradient of their corresponding colors? In a basic example of


\node[circle,fill=blue] (par) at (0,0) {Parent}
    [level distance=4cm,sibling angle=25,clockwise from=80]
    child {node[circle,fill=red] (child1) {Child 1}}
    child {node[circle,fill=yellow] (child2) {Child 2}}
    child {node[circle,fill=green] (child3) {Child 3}};


enter image description here

How to make a gradient of blue ... red for the line connecting the parent to the first child, blue ... yellow for the second child, etc.


I don't know how to do this with a tree and child but it's possible like this :



         start color/.store in =\startcolor,
         end color/.store in   =\endcolor

\pgfdeclaredecoration{color change}{initial}{
 \state{initial}[width=0pt, next state=line, persistent precomputation={%
 \state{line}[width=.5pt,   persistent postcomputation={%

\begin{tikzpicture}[every node/.style={circle,minimum width=1cm,font=\small},line width=1.6pt] 
  \node [fill=blue] (P) {Parent};
  \node [fill=red]    (C1) at (0:3)  {Child 1};
  \node [fill=yellow] (C2) at (30:3) {Child 2}; 
  \node [fill=green]  (C3) at (60:3) {Child 3};  
    \draw[line width=2pt, 
          decoration={color change, start color=blue, end color=red},
          decorate] (P) -- (C1) ;
\draw[line width = 2pt, 
      decoration = {color change, start color=blue, end color=yellow}, 
          decorate] (P) -- (C2) ;   
\draw[line width = 2pt, 
      decoration = {color change, start color=blue, end color=green}, 
          decorate] (P) -- (C3) ;   


enter image description here

| improve this answer | |
  • This works well, but the only problem is that the start-end colors should be defined manually, and it will not detect them from the node colors. Anyway, it is not a normal tree, and lines should be drawn individually. – Googlebot Jun 4 '12 at 19:43
  • Yes you need to add color manually but I don't know how to use the color of the nodes. – Alain Matthes Jun 4 '12 at 19:54
  • Maybe make the connecting lines a little thicker? Like 1/3 the diameter of the circles? – Todd Lehman Jun 4 '12 at 20:32
  • This is awesome. Can the color change decoration be made to work with arrows? Right now, a final arrowhead can point in the wrong direction when using -| and -| to construct paths. – Neil G Jun 20 '12 at 2:13

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.