
решение1
Вы имеете в виду вот так? Просто добавьте tikz
параметры рисования после текста узла (например, draw=red
, fill=green
, и text=blue
). Вы можете удалить круги для данного узла, добавив draw=none
.
\documentclass{article}
\usepackage{forest}
\begin{document}
\large
\begin{forest}
for tree={circle,draw, l sep=10pt}
[36,draw=none
[2,fill=red]
[18,draw=none
[2,fill=yellow]
[9,draw=none
[3,fill=green]
[3,fill=cyan]
]
]
]
\end{forest}
\end{document}
Или
\documentclass{article}
\usepackage{forest}
\newcounter{nextcolor}
\xdef\LstColor{{"red","yellow","green","blue","orange","magenta","cyan"}}
\tikzset{fill next color/.style={%
/utils/exec=\pgfmathsetmacro{\mycolor}{\LstColor[\number\value{nextcolor}]}
\stepcounter{nextcolor},
fill=\mycolor}}
\begin{document}
\large
\begin{forest}
for tree={l sep=10pt,
if n children=0{circle,draw,fill next color}{}}
[36,black
[2]
[18
[2]
[9
[3]
[3]
]
]
]
\end{forest}
\end{document}