Alinhamento vertical e horizontal de células em uma tabela com florestas nelas

Alinhamento vertical e horizontal de células em uma tabela com florestas nelas

Aqui está um MWE no qual crio uma tabela com uma linha de texto simples, outra linha com nó tikz e ainda outra com células de floresta. Tento usar a opção [t] no ambiente da tabela para alinhar as células e o especificador de coluna c para centralizar as células verticalmente.

\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}

A saída, entretanto, mostra que isso não funciona

insira a descrição da imagem aqui

Responder1

Existem dois problemas.

  1. Em primeiro lugar, existe um bug no pgf que insere espaços falsos. Uma correção temporária do bug foi fornecidaaqui. Nas versões futuras do pgf, esse bug será corrigido.
  2. Segundo, [t]in \begin{tabular}[t]{...}não alinha a parte superior das células da tabela. Adicionei um tipo de coluna Tque faz isso usando collcelland adjustbox.

Código:

\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}

insira a descrição da imagem aqui

informação relacionada