I am able to generate the following tree using the MWE below. It creates tikzpictures using a \drawtape
command and puts them into saveboxes, which in turn can be straightforwardly used as the content of nodes in a forest
environment.
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\newcommand{\drawtape}[3]{
\begin{tikzpicture}[cell/.style={minimum size=0.5cm,outer sep=0pt,draw,rectangle,node distance=0pt,text height=1.5ex}]
\foreach \x [count=\xi] in {#1} {
\ifnum \xi=1
\node[cell] (\xi) {$\x$};
\else
\pgfmathtruncatemacro{\xil}{\xi - 1}
\node[cell] (\xi) [right=of \xil] {$\x$};
\fi
}
\node[font=\footnotesize] [below=0cm of #2, xshift=0.03em] {$#3$};
\end{tikzpicture}
}
\newsavebox{\treeroot}
\newsavebox{\treeone}
\newsavebox{\treetwo}
\usepackage{forest}
\begin{document}
\savebox{\treeroot}{\drawtape{1, 1, 1}{1}{1}}
\savebox{\treeone}{\drawtape{0, 1, 1, 1}{1}{2}}
\savebox{\treetwo}{\drawtape{1, 1, 1}{2}{1}}
\begin{forest}
[\usebox{\treeroot}
[\usebox{\treeone}]
[\usebox{\treetwo}]
]
\end{forest}
\end{document}
This works okay for small trees like the one pictured, but if I want to create a larger tree then the number of saveboxes I have to manually create quickly becomes incredibly cumbersome. Ideally, I would like to be able to write a forest
environment like the one below instead. Is there any way to achieve this?
\begin{forest}
[\drawtape{1, 1, 1}{1}{1}
[\drawtape{0, 1, 1, 1}{1}{2}]
[\drawtape{1, 1, 1}{2}{1}]
]
\end{forest}