Is there some good tool for drawing binary trees with labels that are rendered by latex? I would need to have the tree node placement done automatically for me, because there are too many labels to calculate their placing manually.
To be more specific. I can easily control the output format of my data. What I can't do is output into a format, where I have to calculate the coordinates for each node. I'd like to output the data into a format for a tool that can calculate the graph layout.
EDIT: I noticed that the solution below doesn't seem to accept math in the labels. For example the code below won't work, but if I drop the dollars around the label "x", then it will. This is a problem, because my labels are 2×2-matrices.
\documentclass[tikz,border=5]{standalone}
\usetikzlibrary{graphs,graphdrawing,arrows.meta}
\usegdlibrary{trees}
\begin{document}
\begin{tikzpicture}[>=Stealth]
\graph[binary tree layout]
{
root->{$x$->{}}
};
\end{tikzpicture}
\end{document}
Best Answer
The most recent release of
PGF
has a number of graph drawing algorithms (requiringlualatex
) including a version of the Reingold–Tilford method and can easily handle large numbers of nodes.In the simplest case a tree can be specified like this:
It is also possible to create "graph macros" which mean the graph specification can be created more-or-less automatically, even using
lua
: