3

How can I have only the last level (leaves) of the tree circled (not everyone)?

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

Graph Example

3

Instead of applying the style to every node, make a new style circnode that you apply only to selected nodes.

Alternatively, you could consider using forest where this is really easy.

\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}
0

I also stumbled upon this solution before reading 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}

enter image description here

  • 2
    Note that \tikzstyle is deprecated. – cfr Jul 5 '17 at 21:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.