我有一个forest
,其节点为tabular
s,如下所示:
我希望边缘
- 与表格第二列(公式)的中心对齐 - 即在上端,即父表第二列的中心,在下端,即子表第二列的中心 - 而不是节点的中心,即整个表格宽度的中心;
- -- 使用 js bibra 的答案解决 --从中心开始,而不是围绕中心对称地保持一定距离,以便所有子项的边缘都在顶部相遇:
我知道有一个选项可以设置anchor
s,但是我如何将它指向节点内列的中心?我想我可以设置\tikzmark
s 并让边分别在 、 处开始和结束lastformulaparent.center
,firstformulachild.center
但是,如果我可以的话,我如何才能通用地做到这一点,而不必为每个节点设置新的 tikzmarks 和自定义边?
\documentclass{article}
% math formatting
\usepackage{amssymb, amsmath, amstext}
% tableau trees
\usepackage{forest}
\forestset{qtree/.style={for tree={parent anchor=south:
child anchor=north,align=center,inner sep=0pt}}}
\begin{document}
\begin{forest}
[
\begin{tabular}{lcl}
\underline{1.} & $\neg \exists y \forall x P(x{,}\ \!y)$ & (A)\\
\underline{2.} & $\forall x \exists y P(x{,}\ \!y)$ & (A)\\
\underline{3.} & $\exists y P(a{,}\ \!y)$ & ($\forall{,}\ 2{,}\ \lbrack x/a \rbrack*$)\\
\underline{4.} & $\neg \forall x P(x{,}\ \!a)$ & ($\neg \exists{,}\ 1{,}\ \lbrack y/a \rbrack$)
\end{tabular}
[
\begin{tabular}{lcl}
5. & $\neg P(a{,}\ \!a)$ & ($\neg \forall{,}\ 4{,}\ \lbrack x/a \rbrack$)
\end{tabular}
[
\begin{tabular}{lcl}
6. & $P(a{,}\ \!a)$ & ($\exists{,}\ 3{,}\ \lbrack y/a \rbrack$)\\
& $\times$ & ($5{,}\ 6$)
\end{tabular}
]
]
[
\begin{tabular}{lcl}
\underline{7.} & \underline{$\neg P(b{,}\ \!a)$} & ($\neg \forall{,}\ 4{,}\ \lbrack x/b \rbrack*$)
\end{tabular}
[
\begin{tabular}{lcl}
\underline{8.} & \underline{$P(a{,}\ \!a)$} & ($\exists{,}\ 3{,}\ \lbrack y/a \rbrack$)\\
\underline{9.} & $\exists y P(b{,}\ \!y)$ & ($\forall{,}\ 2{,}\ \lbrack x/b \rbrack$)
\end{tabular}
[
\begin{tabular}{lcl}
10. & $P(b{,}\ \!a)$ & ($\exists{,}\ 9{,}\ \lbrack y/a \rbrack$)\\
& $\times$ & ($7{,}\ 10$)
\end{tabular}
]
[
\begin{tabular}{lcl}
\underline{11.} & \underline{$P(b{,}\ \!b)$} & ($\exists{,}\ 9{,}\ \lbrack y/b \rbrack$)\\
\underline{12.} & $\neg \forall x P(x{,}\ \!b)$ & ($\neg \exists{,}\ 1{,}\ \lbrack y/b \rbrack$)
\end{tabular}
[
\begin{tabular}{lcl}
\underline{13.} & \underline{$\neg P(a{,}\ \!b)$} & ($\neg \forall{,}\ 12{,}\ \lbrack x/a \rbrack$)\\
\underline{} & $\circ$ &
\end{tabular}
]
]
]
]
]
\end{forest}
\end{document}
答案1
根据 js bibra 的回答,您可以将每个表格的第一列和第三列设置为相同的固定值(更改lcl
为p{1em}cp{1em}
);每个表格的中心将成为公式列的中心。
据我所知,这样做需要付出一些小小的代价:你必须忍受一些Overfull \hbox
抱怨,并且你需要s sep
在树的适当位置添加一些键来阻止分支碰撞(参见下面代码中的第 23 行和第 43 行)。
但至少输出最终是令人满意的。
感兴趣的读者可以参考我的问题使用森林排版的逻辑证明树中跨节点的良好对齐寻找一种这样做的方法,避免必须创建多行表格(尽管有一些权衡)。
\documentclass{article}
% math formatting
\usepackage{amssymb, amsmath, amstext}
% tableau trees
\usepackage{forest}
\begin{document}
\begin{forest}
for tree={for tree={parent anchor=south,
child anchor=north,
align=center,
inner sep=0pt}}
[
\begin{tabular}{p{1em}cp{1em}}
\underline{1.} & $\neg \exists y \forall x P(x{,}\ \!y)$ & (A)\\
\underline{2.} & $\forall x \exists y P(x{,}\ \!y)$ & (A)\\
\underline{3.} & $\exists y P(a{,}\ \!y)$ & ($\forall{,}\ 2{,}\ \lbrack x/a \rbrack*$)\\
\underline{4.} & $\neg \forall x P(x{,}\ \!a)$ & ($\neg \exists{,}\ 1{,}\ \lbrack y/a \rbrack$)
\end{tabular}, s sep=6em
[
\begin{tabular}{p{1em}cp{1em}}
5. & $\neg P(a{,}\ \!a)$ & ($\neg \forall{,}\ 4{,}\ \lbrack x/a \rbrack$)
\end{tabular}
[
\begin{tabular}{p{1em}cp{1em}}
6. & $P(a{,}\ \!a)$ & ($\exists{,}\ 3{,}\ \lbrack y/a \rbrack$)\\
& $\times$ & ($5{,}\ 6$)
\end{tabular}
]
]
[
\begin{tabular}{p{1em}cp{1em}}
\underline{7.} & \underline{$\neg P(b{,}\ \!a)$} & ($\neg \forall{,}\ 4{,}\ \lbrack x/b \rbrack*$)
\end{tabular}
[
\begin{tabular}{p{1em}cp{1em}}
\underline{8.} & \underline{$P(a{,}\ \!a)$} & ($\exists{,}\ 3{,}\ \lbrack y/a \rbrack$)\\
\underline{9.} & $\exists y P(b{,}\ \!y)$ & ($\forall{,}\ 2{,}\ \lbrack x/b \rbrack$)
\end{tabular}, s sep=5em
[
\begin{tabular}{p{1em}cp{1em}}
10. & $P(b{,}\ \!a)$ & ($\exists{,}\ 9{,}\ \lbrack y/a \rbrack$)\\
& $\times$ & ($7{,}\ 10$)
\end{tabular}
]
[
\begin{tabular}{p{1em}cp{1em}}
\underline{11.} & \underline{$P(b{,}\ \!b)$} & ($\exists{,}\ 9{,}\ \lbrack y/b \rbrack$)\\
\underline{12.} & $\neg \forall x P(x{,}\ \!b)$ & ($\neg \exists{,}\ 1{,}\ \lbrack y/b \rbrack$)
\end{tabular}
[
\begin{tabular}{p{1em}cp{1em}}
\underline{13.} & \underline{$\neg P(a{,}\ \!b)$} & ($\neg \forall{,}\ 12{,}\ \lbrack x/a \rbrack$)\\
\underline{} & $\circ$ &
\end{tabular}
]
]
]
]
]
\end{forest}
\end{document}
答案2
删除\forestset
序言中的
\forestset{qtree/.style={for tree={parent anchor=south:
child anchor=north,align=center,inner sep=0pt}}}
并在后面添加以下定义\begin{document}
for tree={for tree={parent anchor=south,
child anchor=north,
align=center,
inner sep=0pt}}
平均能量损失
\documentclass{article}
% math formatting
\usepackage{amssymb, amsmath, amstext}
% tableau trees
\usepackage{forest}
\begin{document}
\begin{forest}
for tree={for tree={parent anchor=south,
child anchor=north,
align=center,
inner sep=0pt}}
[
\begin{tabular}{lcl}
\underline{1.} & $\neg \exists y \forall x P(x{,}\ \!y)$ & (A)\\
\underline{2.} & $\forall x \exists y P(x{,}\ \!y)$ & (A)\\
\underline{3.} & $\exists y P(a{,}\ \!y)$ & ($\forall{,}\ 2{,}\ \lbrack x/a \rbrack*$)\\
\underline{4.} & $\neg \forall x P(x{,}\ \!a)$ & ($\neg \exists{,}\ 1{,}\ \lbrack y/a \rbrack$)
\end{tabular}
[
\begin{tabular}{lcl}
5. & $\neg P(a{,}\ \!a)$ & ($\neg \forall{,}\ 4{,}\ \lbrack x/a \rbrack$)
\end{tabular}
[
\begin{tabular}{lcl}
6. & $P(a{,}\ \!a)$ & ($\exists{,}\ 3{,}\ \lbrack y/a \rbrack$)\\
& $\times$ & ($5{,}\ 6$)
\end{tabular}
]
]
[
\begin{tabular}{lcl}
\underline{7.} & \underline{$\neg P(b{,}\ \!a)$} & ($\neg \forall{,}\ 4{,}\ \lbrack x/b \rbrack*$)
\end{tabular}
[
\begin{tabular}{lcl}
\underline{8.} & \underline{$P(a{,}\ \!a)$} & ($\exists{,}\ 3{,}\ \lbrack y/a \rbrack$)\\
\underline{9.} & $\exists y P(b{,}\ \!y)$ & ($\forall{,}\ 2{,}\ \lbrack x/b \rbrack$)
\end{tabular}
[
\begin{tabular}{lcl}
10. & $P(b{,}\ \!a)$ & ($\exists{,}\ 9{,}\ \lbrack y/a \rbrack$)\\
& $\times$ & ($7{,}\ 10$)
\end{tabular}
]
[
\begin{tabular}{lcl}
\underline{11.} & \underline{$P(b{,}\ \!b)$} & ($\exists{,}\ 9{,}\ \lbrack y/b \rbrack$)\\
\underline{12.} & $\neg \forall x P(x{,}\ \!b)$ & ($\neg \exists{,}\ 1{,}\ \lbrack y/b \rbrack$)
\end{tabular}
[
\begin{tabular}{lcl}
\underline{13.} & \underline{$\neg P(a{,}\ \!b)$} & ($\neg \forall{,}\ 12{,}\ \lbrack x/a \rbrack$)\\
\underline{} & $\circ$ &
\end{tabular}
]
]
]
]
]
\end{forest}
\end{document}