Como posso ter apenas o último nível (folhas) da árvore circulado (nem todos)?
\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{graphdrawing}
\usetikzlibrary{graphs}
\usegdlibrary{trees}
\begin{document}
\tikzset{ every node/.style={circle, draw, fill=gray!10,, minimum size=0.75cm} }
\begin{tikzpicture}[>=stealth]
\graph [tree layout, grow=down, fresh nodes, level distance=0.5in, sibling distance=0.5in]
{
200 -> {
5 -> { 2, 2.5 },
40 -> { 5 -> {2, 2.5 }, 8->{2,4} }
}
};
\end{tikzpicture}
\end{document}
Responder1
Em vez de aplicar o estilo a every node
, crie um novo estilo circnode
que será aplicado somente aos nós selecionados.
Alternativamente, você pode considerar usar forest
onde isso for realmente fácil.
\RequirePackage{luatex85}
\documentclass[tikz,border=10pt]{standalone}
\usepackage{forest}
\usetikzlibrary{graphdrawing}
\usetikzlibrary{graphs}
\usegdlibrary{trees}
\begin{document}
\tikzset{ circnode/.style={circle, draw, fill=gray!10,, minimum size=0.75cm} }
\begin{tikzpicture}[>=stealth]
\graph [tree layout, grow=down, fresh nodes, level distance=0.5in, sibling distance=0.5in]
{
200 -> {
5 -> { 2 [circnode], 2.5 [circnode]},
40 -> { 5 -> {2[circnode], 2.5[circnode] }, 8->{2[circnode],4[circnode]} }
}
};
\end{tikzpicture}
\begin{forest}
for tree={l=0.5in,s sep=5mm,edge={-stealth}},
where n children=0{circnode}{}
[200
[5
[2][2.5]
]
[40
[5
[2][2.5]
]
[8
[2][4]
]
]
]
\end{forest}
\end{document}
Responder2
Também me deparei com esta solução antes de ler Torbjorn, T.
\tikzstyle{leaves}=[circle, draw, fill=gray!10, minimum size=0.75cm]
\begin{tikzpicture}[>=stealth]
\graph [tree layout, grow=down, fresh nodes, level distance=0.5in, sibling distance=0.5in]
{
200 -> {
5 -> { 2[leaves], 2.5[leaves] },
40 -> { 5 -> {2[leaves], 2.5[leaves] }, 8-> {2[leaves],4[leaves]} }
}
};
\end{tikzpicture}