下面是一个 MWE,我在其中创建了一个表格,其中一行是纯文本,另一行是 tikz 节点,还有一行是森林单元格。我尝试使用表格环境中的 [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
有两个问题。
- 首先,pgf 中有一个错误,会插入虚假空格。已提供该错误的临时修复程序这里在pgf未来的版本中,这个bug将会被修复。
- 其次,
[t]
in\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}