2

Here is a MWE in which I create a table with one row of plain text, another row with tikz node, and yet another one with forest cells. I try to use the [t] option to the table environment to top align the cells and column specifier c to center the cells vertically.

\documentclass{standalone}
\usepackage{forest}
\begin{document}
\forestset{c/.style={circle,draw},t/.style={},}
\def\bb{ \draw[fill=blue,opacity=0.2] (current bounding box.south west) rectangle (current bounding box.north east);}
\def\xx#1#2{
  #1
  \begin{tikzpicture}
    \node [fill=green,opacity=0.2,draw,minimum width=#1cm, minimum height=#2cm] {#1#2};
  \end{tikzpicture}
  #2
}
\begin{tabular}[t]{|c|c|c|c|c|c|}
  $(ab.cd)$                                                           &
  $(abcd.\bot)$                                                       &
  $(ab.(c.d))$                                                        &
  $((a.b).(c.d))$                                                     &
  $(a.(b.(c.d)))$                                                     &
  $(((a.b).c).d)$                                                       \\
  \hline
  \xx23                                                               &
  \xx34                                                               &
  \xx24                                                               &
  \xx14                                                               &
  \xx41                                                               &
  \xx43                                                                 \\
  \hline
  \scriptsize
  \Forest{for tree [{},c[$ab$,t][$cd$,t]]\bb}                         &
  \scriptsize
  \Forest{for tree [{},c[$abcd$,t][$\bot$,t]]\bb}                     &
  \scriptsize
  \Forest{for tree [{},c[$ab$,t][{},c[$c$,t][$d$,t]]]\bb}             &
  \scriptsize
  \Forest{for tree [{},c[{},c[$a$,t][$b$,t]][{},c[$c$,t][$d$,t]]]\bb} &
  \scriptsize
  \Forest{for tree [{},c [{},c [{},c[a,t][b,t]] [c,t]] [d,t] ] \bb}   &
  \scriptsize
  \Forest{for tree [{},c [{}, c [{}, c
        [a,t][b,t]] [c,t] ] [d,t]] \bb}
\end{tabular}
\end{document}

The output however shows that this does not work

enter image description here

0
2

There are two issues.

  1. First and foremost, there is a bug in pgf that inserts spurious spaces. A temporary fix of the bug has been provided here. In future versions of pgf, this bug will be fixed.
  2. Second, [t] in \begin{tabular}[t]{...} does not top-align the cells in the table. I added a column type T that does that using collcell and adjustbox.

Code:

\documentclass{standalone}
\usepackage{forest}
\usepackage{adjustbox}
\usepackage{collcell}
\makeatletter
% remove the stray space https://tex.stackexchange.com/a/513549
\patchcmd{\pgfutilsolvetwotwoleqfloat}
  { \noexpand\pgfmathfloatdivide@}
  {\noexpand\pgfmathfloatdivide@}
  {}{}
\makeatother
\newcommand{\TopAlign}[1]{\adjustbox{valign=t}{#1}}
\newcolumntype{T}{>{\collectcell{\TopAlign}}c<{\endcollectcell}}

\begin{document}
\forestset{c/.style={circle,draw},t/.style={},}
\def\bb{ \draw[fill=blue,opacity=0.2] (current bounding box.south west) rectangle (current bounding box.north east);}
\def\xx#1#2{
  #1
  \begin{tikzpicture}
    \node [fill=green,opacity=0.2,draw,minimum width=#1cm, minimum height=#2cm] {#1#2};
  \end{tikzpicture}
  #2
}
\begin{tabular}{*{6}{|T}|}
  $(ab.cd)$                                                           &
  $(abcd.\bot)$                                                       &
  $(ab.(c.d))$                                                        &
  $((a.b).(c.d))$                                                     &
  $(a.(b.(c.d)))$                                                     &
  $(((a.b).c).d)$                                                       \\
  \hline
  \xx23                                         &
  \xx34                                                              &
  \xx24                                                             &
  \xx14                                                              &
  \xx41                                                              &
  \xx43                                                                \\
  \hline
  \scriptsize
  \Forest{for tree [{},c[$ab$,t][$cd$,t]]\bb}                         &
  \scriptsize
  \Forest{for tree [{},c[$abcd$,t][$\bot$,t]]\bb}                     &
  \scriptsize
  \Forest{for tree [{},c[$ab$,t][{},c[$c$,t][$d$,t]]]\bb}             &
  \scriptsize
  \Forest{for tree [{},c[{},c[$a$,t][$b$,t]][{},c[$c$,t][$d$,t]]]\bb} &
  \scriptsize
  \Forest{for tree [{},c [{},c [{},c[a,t][b,t]] [c,t]] [d,t] ] \bb}   &
  \scriptsize
  \Forest{for tree [{},c [{}, c [{}, c
        [a,t][b,t]] [c,t] ] [d,t]] \bb}
\end{tabular}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.