
これは、プレーン テキストの 1 行、tikz ノードの別の行、およびフォレスト セルの別の行を含むテーブルを作成する MWE です。テーブル環境の [t] オプションを使用してセルを上揃えにし、列指定子 c を使用してセルを垂直方向に中央揃えにするようにしています。
\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}
しかし、出力はこれが機能しないことを示しています
答え1
問題は2つあります。
- まず第一に、pgfには不必要なスペースを挿入するバグがあります。このバグの一時的な修正が提供されています。ここpgf の将来のバージョンでは、このバグは修正される予定です。
- 2 番目に、
[t]
では\begin{tabular}[t]{...}
テーブル内のセルが上揃えになりません。と をT
使用して、これを実現する列タイプを追加しました。collcell
adjustbox
コード:
\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}