원을 제거하고 트리 요소에 색상을 추가하세요.

원을 제거하고 트리 요소에 색상을 추가하세요.

질문: 아래에 추가된 이미지를 찾고 있습니다. 그리고 모든 노드에 서로 다른 색상을 추가하고 싶습니다.

지금까지 내가 한 일은 다음과 같습니다.

\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=greentext=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}

관련 정보