如何在 Tikz 中圈出树枝

如何在 Tikz 中圈出树枝

我想知道如何围绕树枝,就像图中所示的那样。

这是我目前所拥有的

 \begin{tikzpicture}
    \node[circle,draw,fill=gray]{s}
        child{node[circle,draw,fill=white]{}
             child{node[circle,draw,fill=gray]{}}
        }
        child{node[circle,draw,fill=white]{}
             child{node[circle,draw,fill=gray]{}}
        }
        child{node[circle,draw,fill=white]{}
            child{node[circle,draw,fill=gray]{}}
        };
\end{tikzpicture}

tikz 树

答案1

欢迎!绘制这种光环的方法有很多种,这里是其中一种。

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{backgrounds}
\begin{document}

\begin{tikzpicture}[halo/.style={line join=round,
 double,line cap=round,double distance=#1,shorten >=-#1/2,shorten <=-#1/2},
 halo/.default=7mm]
    \node[circle,draw,fill=gray](s){s}
        child{node[circle,draw,fill=white]{}
             child{node[circle,draw,fill=gray]{}}
        }
        child{node[circle,draw,fill=white]{}
             child{node[circle,draw,fill=gray]{}}
        }
        child{node[circle,draw,fill=white](R1){}
            child{node[circle,draw,fill=gray](R2){}}
        };
 \begin{scope}[on background layer]     
  \draw[halo] (s) -- (R1.center) -- (R2);       
 \end{scope}
 \path (R2.south) ++ (0,-3.5mm); % shorten does not get taken into account by the bounding box
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容