3

I created some code based on an answer here: Drawing binary trees with LaTeX labels.

\documentclass[tikz,border=5]{standalone}
\usetikzlibrary{graphs,graphdrawing,graphs.standard,arrows.meta}
\usegdlibrary{trees}
\begin{document}
\tikzgraphsset{%
  levels/.store in=\tikzgraphlevel,
  levels=1,
  declare={full_binary_tree}{[
    /utils/exec={
      \edef\treenodes{%
\directlua{%
  function treenodes(l)
    if l == 0 then
      return "/"
    else
      return "/ [layer distance=" .. l*10 .. "]-> {" .. treenodes(l-1) .. ", " .. treenodes(l-1) .. "}"
    end
  end
  tex.print(treenodes(\tikzgraphlevel) .. ";")
}%
      }
    },
    parse/.expand once=\treenodes
  ]}
}
\begin{tikzpicture}
\graph[binary tree layout, grow=down, sibling distance=0pt, significant sep=-5pt, nodes={fill=red, draw=none, circle, inner sep=4pt, outer sep=0pt}, edge={style={very thick}}]{
   full_binary_tree [levels=5];
};
\end{tikzpicture}
\end{document}

Compile this with lualatex and you get this:

Typeset image

Question: Can anyone suggest an edit to the script above, to terminate the tree with nodes that are vertical ellipsis (three vertical dots) indicating an infinite regression of the tree downwards?

Thus, the lowest row of nodes (and only the lowest row) would be styled differently so they are ellipsis dots instead of red circles.

Thanks.

1 Answer 1

3

While you're waiting for a lua solution, here is a possibility with forest.

enter image description here

\documentclass{article}

\usepackage{forest}
\tikzset{mynode/.style={fill=red, circle, minimum size=3.5mm}}

\begin{document}

\begin{forest}
before typesetting nodes={for tree={if n children=0{content={$\vdots$}}{mynode}, edge={very thick, ->}, inner sep=0pt, s sep=3mm, outer sep=0pt}}
  [,repeat=2{append={[,repeat=2{append={[,repeat=2{append={[,repeat=2{append={[,repeat=2{append={[]}}]}}]}}]}}]}}]
\end{forest}

\end{document}
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .