円を削除し、ツリーの要素に色を追加します

円を削除し、ツリーの要素に色を追加します

質問: 以下に追加された画像を探しています。そして、各ノードに異なる色を追加したいと考えています。

これまで私がやったことは以下の通りです。

\documentclass{article} 
\usepackage{forest}

\begin{document}
    \large
    \begin{forest}
        for tree={circle,draw, l sep=10pt}
        [36,black 
        [2]
        [18
        [2] 
        [9
        [3]
        [3]
        ]       
        ]
        ]
        \end{forest}
\end{document}

ここに画像の説明を入力してください

答え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}

関連情報