3

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:

trees in table

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}
1
  • Welcome to TeX.SE! Please post an MWE so folks here can compile the whole document and test it out. May 30, 2019 at 2:12

1 Answer 1

5

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}

enter image description here

3
  • Yes, this worked beautifully thanks. Can you explain how you got this result?
    – antonky
    May 30, 2019 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, 2019 at 2:33
  • 1
    Oh I some how didn't notice those, that explains it fine thanks.
    – antonky
    May 30, 2019 at 2:34

You must log in to answer this question.

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