# Putting forest trees in table cells

I would like to put a forest tree in each cell of the first column of a table. There are some issues when I do this: The spacing is too tight, and the numbers in the rest of the table go to the bottom. I don't really know enough about how to use forest to figure out how to add spacing around it, and I also don't know how it interacts with latex tables. Here's what it looks like right now:

MWE:

\documentclass{article}
\begin{document}
\begin{equation*}
\begin{array}{|c|c|c|}\hline
\text{Tree} & N_L(T) & \frac{1}{3}N(T) \\\hline
\begin{forest}
for tree={ grow=south, circle, draw, minimum size=3ex, inner sep=1pt, s sep=3mm }
[]
\end{forest}
& 1      & \frac{1}{3}     \\\hline
\begin{forest}
for tree={ grow=south, circle, draw, minimum size=3ex, inner sep=1pt, s sep=3mm }
[[,no edge, draw=none][]]
\end{forest}
& 1      & \frac{2}{3}     \\\hline
\begin{forest}
for tree={ grow=south, circle, draw, minimum size=3ex, inner sep=1pt, s sep=3mm }
[[][,no edge, draw=none]]
\end{forest}
& 1      & \frac{2}{3}     \\\hline
\begin{forest}
for tree={ grow=south, circle, draw, minimum size=3ex, inner sep=1pt, s sep=3mm }
[[][]]
\end{forest}
& 2      & 1               \\\hline
\end{array}
\end{equation*}
\end{document}

• Welcome to TeX.SE! Please post an MWE so folks here can compile the whole document and test it out. – LarrySnyder610 May 30 '19 at 2:12

Here is a proposal.

1. The forests are wrapped into \vcenter{\hbox{...}} to vertically center them.
2. forest is based on TikZ, and in the equation, i.e. locally, every tikzpicture's bounding box is increased. This allows one to obtain a finer control of the padding than with the standard methods like \renewcommand{\arraystretch}{...} or \\[...].

\documentclass{article}
\usepackage{amsmath}
\usepackage{forest}
\begin{document}
\begin{equation*}\tikzset{every picture/.append style={execute at end picture={%
\path (current bounding box.north)  +(0,1ex) (current bounding box.south) +(0,-1ex);}}}
\begin{array}{|c|c|c|}\hline
\text{Tree} & N_L(T) & \frac{1}{3}N(T) \\\hline
\vcenter{\hbox{\begin{forest}
for tree={ grow=south, circle, draw, minimum size=3ex, inner sep=1pt, s sep=3mm }
[]
\end{forest}}}
& 1      & \frac{1}{3}     \\\hline
\vcenter{\hbox{\begin{forest}
for tree={ grow=south, circle, draw, minimum size=3ex, inner sep=1pt, s sep=3mm }
[[,no edge, draw=none][]]
\end{forest}}}
& 1      & \frac{2}{3}     \\\hline
\vcenter{\hbox{\begin{forest}
for tree={ grow=south, circle, draw, minimum size=3ex, inner sep=1pt, s sep=3mm }
[[][,no edge, draw=none]]
\end{forest}}}
& 1      & \frac{2}{3}     \\\hline
\vcenter{\hbox{\begin{forest}
for tree={ grow=south, circle, draw, minimum size=3ex, inner sep=1pt, s sep=3mm }
[[][]]
\end{forest}}}
& 2      & 1               \\\hline
\end{array}
\end{equation*}
\end{document}


• Yes, this worked beautifully thanks. Can you explain how you got this result? – nakamin May 30 '19 at 2:31
• @nakamin You're welcome! I tried to do so in items 1 and 2. I'll be happy to extend the explanation if you give me a hint what I should explain more. – user121799 May 30 '19 at 2:33
• Oh I some how didn't notice those, that explains it fine thanks. – nakamin May 30 '19 at 2:34