1

I have a forest whose nodes are tabulars, looking like this:

enter image description here

I would like the edges to

  1. be aligned to the center of the second column of the table (the formulas) -- that is, at the upper end, the center of the second column of the parent table and at the lower end, the center of the second column of the child table -- rather than the center of the node, which is the center of the entire table width;
  2. -- solved with js bibra's answer -- start right in the center rather than with some distance symmetrically around the center, so that the edges to all children meet at the top:

enter image description here

I know that there is an option to set the anchors, but how do I point it to the center of a column inside the node? I suppose I could set \tikzmarks and have the edge start and end at lastformulaparent.center, firstformulachild.center, respectively, but how, if at all, could I do this generically without having to set new tikzmarks and custom edges for every node?

\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}
3
  • 1
    There's a typo in your qtree style: it should read anchor=south, not anchor=south:. And you need to apply it to your tree by using \begin{forest}qtree .... This is what @jsbibra's solution does, effectively so you had the solution at hand already.
    – Alan Munn
    Aug 12, 2020 at 14:11
  • 1
    But if you load forest with the linguistics option, that will be the default style anyway.
    – Alan Munn
    Aug 12, 2020 at 15:02
  • @Alan Munn Oh, that makes sense. I'll go with the linguistics option then; thanks. Aug 12, 2020 at 20:40

2 Answers 2

1

Building upon js bibra's answer, you can set the first and third columns of each tabular to the same fixed value (change lcl to p{1em}cp{1em}); the centre of each tabular will then be the centre of the formula column.

As far as I can tell there are a few minor prices to pay for doing this: you have to live with a couple of Overfull \hbox complaints, and you need to add some s sep keys at appropriate points in the tree to stop branches colliding (see lines 23 and 43 in the code below).

But at least the output is finally pleasingly aligned.

Interested readers might like to refer to my question at Nice alignment across nodes in logic proof trees typeset with forest for a way of doing something like this that avoids having to create multirow tabulars (although there are some tradeoffs).

The centres of the formulas are now pleasingly aligned down the middle of the branch

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

Delete the \forestset in the preamble

\forestset{qtree/.style={for tree={parent anchor=south: 
           child anchor=north,align=center,inner sep=0pt}}}

And add the following definition after \begin{document}

for tree={for tree={parent anchor=south,
        child anchor=north,
        align=center,
        inner sep=0pt}}

enter image description here

MWE

\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}
3
  • This solves the second part; thanks! Aug 12, 2020 at 13:59
  • This is the same style as the qtree style in the question, except that there was a typo in that style and it hadn't been applied to the tree anyway. So a simpler solution is fix the style and apply it to the tree.
    – Alan Munn
    Aug 12, 2020 at 14:13
  • But this style isn't needed at all if forest is loaded with the linguistics option.
    – Alan Munn
    Aug 12, 2020 at 15:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .