10

I would like to make something similar to the logic tree below. I've tried using tikz-qtree, but I can't figure out how to number every line in the tree. I did however find something else doable in qtree. Here's a sample of my code (note that it's not the same tree as below)

    \documentclass[a4paper, english, 12pt, reqno]{article}\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[norsk]{babel}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{mathtools}
\usepackage[shortlabels]{enumitem}
\usepackage{bm}
\usepackage{qtree}

\begin{document}
\maketitle{}

\section{}
\begin{center}
\begin{tabular}{c  c  c}
\Tree[.{1\\2\\ 3\\4} [.5  [.6 ] ] ] &
\Tree[.$A\supset B$\\$C\vee A$\\$\sim\sim C$\,\checkmark\\$C$ [.$C$ $s$ $s$ ][.$A$ $c$ $c$ ] ] &
\Tree[.SM\\SM\\SM\\3$\sim\sim$D [.3$\vee$D [.1$\supset$D ] ] ]
\end{tabular}
\end{center}

\end{document}

So I have some questions, which I hope will be able to help me get closer to a similar tree as in the picture.

1) My lines are not aligned horizontally, any ideas on how to fix that?

2) How can I remove the lines that connects the numbers, and the notation on the right side of the tabular enviroment?

3) This question is not about my code, but I will have this problem later. As you see on line 9 in the picture, there is a node all the way down to the 12th line, skipping the lines in between. How do I do this?

I'm open for using tikz-qtree too, and I probably missed something in the manual, so I will try to read more, as I'm quite new to using qtree in LaTeX. Thanks in advance!

Logic tree example

3

This is a variant of Ignasi's answer. It uses a new package based on forest. The advantage is that the lines are automatically numbered, the justifications are added as annotations with their nodes using the key just (no need for a separate tree) and the vertical spacing between lines which should be grouped together (as when listing assumptions) is corrected automatically. In addition, styles are provided to move nodes (move by) to lower lines in the tree without the need to set special tier names or enter empty nodes. Cross-referencing support is provided in justifications and closure annotations (using either named nodes or relative node names), so that line numbers need not be hard-coded. Further options and details are explained in the package documentation.

\documentclass[tikz,multi,border=10pt]{standalone}
\usepackage{prooftrees,amsmath,turnstile}
\newcommand*{\tnot}{\ensuremath{\mathord{\sim}}}
\begin{document}
\begin{prooftree} % uses Ignasi's code for the main tree (https://tex.stackexchange.com/a/233576/)
  {
    to prove={(\exists x)Fx \supset (\forall x)Fx \sststile{}{} (\forall x) (Fx \supset (\forall y) Fy)}
  }
    [(\exists x) Fx \supset (\forall x) Fx, checked, just=SM, name=pr
      [\tnot (\forall x) (Fx \supset (\forall y) Fy), checked, grouped, just=SM
        [(\exists x) \tnot (Fx \supset (\forall y) Fy), checked=a, just={$\tnot\forall$D:!u}
          [\tnot (Fa \supset (\forall y) Fy), checked, just={$\exists$D:!u}
            [Fa, just={$\tnot\supset$D:!u}, name=fa
              [\tnot (\forall y) Fy, checked, grouped, just={$\tnot\supset$D:!uu}
                [(\exists y) \tnot Fy, checked=b, just={$\tnot\forall$D:!u}
                  [\tnot Fb, just={$\exists$D:!u}, name=nofb
                    [\tnot (\exists x) Fx, checked, just={$\supset$D:pr}
                      [(\forall x) \tnot Fx, subs=a, just={$\tnot\exists$D:!u}
                        [\tnot Fa, close={:fa,!c}, just={$\forall$D:!u}
                        ]
                      ]
                    ]
                    [(\forall x) Fx, subs=b
                      [Fb, close={:nofb,!c}, just={$\forall$D:!u}, move by=2
                      ]
                    ]
                  ]
                ]
              ]
            ]
          ]
        ]
      ]
    ]
\end{prooftree}
\end{document}

prooftrees proof tree

5

Here's one way. This is somewhat of a hack because it requires manual adjustment to get the spacing right.

The code works by creating three trees - the main tree, the line numbers and the justifications. To create the latter two without lines, we temporarily redefine the commands used for branches, making use of qtree's ! feature.

The best work flow involves setting the tree itself first. Then copy that tree above it in your code and replace every instance of [.{single formula i.e. no line break} by [.n for the appropriate line number, n. Then replace [.{several formulae with line breaks} by [.{n\\m\\...} for the relevant line numbers n, m, .... Now compile and check the spacing. Add spacing as required. Get the lines to line up at this point as well as you can. Then copy your line number tree below the code for the main tree. Simply replace the line numbers by the relevant justifications. The spacing should be right as you've already adjusted it.

Getting the long branch down for the twelfth line is actually covered (kind of) in qtree's documentation where it explains how to create nodes without labels. However, it might not be obviously applicable here since the example concerns an unlabelled branching node whereas your example needs extra non-branching nodes.

\documentclass[a4paper, english, 12pt, reqno]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[norsk]{babel}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{mathtools}
\usepackage[shortlabels]{enumitem}
\usepackage{bm}
\usepackage{qtree}
\usepackage{turnstile}
% set up a more semantically pleasing command for not
\newcommand*{\tnot}{\ensuremath{\mathord{\sim}}}
\makeatletter
  \newcommand{\nounibranches}[1]{% One-branching only
      \begin{picture}(0,1)
        \put(0,0){\line(0,1){0}}
      \end{picture}}%
  \newcommand{\nobibranches}[1]{% Two-branching only
      \begin{picture}(2,0.5)
        \put(0,0){\line(2,1){0}}
        \put(2,0){\line(-2,1){0}}
      \end{picture}}%
  \let\qdrawReal=\qdraw@branches
  \def\dimbr#1{\ifcase#1\relax % zero case is unused
    \or  % One-branching
      \let\qdraw@branches=\nounibranches
    \or % Two-branching
      \let\qdraw@branches=\nobibranches
    \else \typeout{error --- Can't handle #1-way branching}
    \fi}
  \newcommand\breto{\let\qdraw@branches=\qdrawReal}
\makeatother

\begin{document}
\hspace*{-\parindent}
{$(\exists x)Fx \supset (\forall x)Fx \sststile{}{} (\forall x) (Fx \subset (\forall y) Fy)$}\bigskip\\
\Tree
  [.{1\\2}
    [.3
      [.4
        [.{5\\6}
          [.7
            [.{8\\[-.75em]\mbox{ }}
              [.9
                [.10
                  [.11
                    [.12
                      !{\dimbr1}
                    ]
                  ]
                ]
              ]
            ]
          ]
        ]
      ]
    ]
  ] {\breto}
\Tree
  [.{$(\exists x) Fx \supset (\forall x) Fx\ \checkmark$\\
    $\tnot (\forall x) (Fx \subset (\forall y) Fy)\  \checkmark$}
      [.{$(\exists x) \tnot (Fx \subset (\forall y) Fy)\ \checkmark$}
        [.{$\tnot (Fa \subset (\forall y) Fy)\ \checkmark$}
           [.{$Fa$\\$\tnot (\forall y) Fy\ \checkmark$}
              [.{$(\exists y) \tnot Fy\ \checkmark$}
                [.{$\tnot Fb$}
                  [.{$\tnot (\exists x) Fx\ \checkmark$}
                    [.{$(\forall x) \tnot Fx\ \checkmark$}
                      [.{$\tnot Fa$\\$\otimes$}
                      ]
                    ]
                  ]
                  [.{$(\forall x) Fx\ \checkmark$}
                    [
                      [
                        [
                          [
                            [
                              [.{$Fb$\\$\otimes$}
                              ]
                             ]
                          ]
                        ]
                      ]
                    ]
                  ]
                ]
              ]
            ]
          ]
      ]
  ]
\Tree
  [.{SM\\SM}
    [.{2 $\tnot\forall$D}
      [.{3 $\exists$E}
        [.{4 $\tnot\supset$D\\4 $\tnot\supset$D}
          [.{6 $\tnot\forall$D}
            [.{7 $\exists$D}
              [.{1 $\supset$D}
                [.{9 $\tnot\exists$D}
                  [.{10 $\forall$D}
                    [.{9 $\forall$D}
                      !{\dimbr1}
                    ]
                  ]
                ]
              ]
            ]
          ]
        ]
      ]
    ]
  ] {\breto}
\end{document}

This produces the following tree:

Tree with line numbers and justifications

  • Thanks for your approach! I've tried both yours and Adam's methods and I just think Adam's just a little bit more cleaner for my taste. As I'm gonna make many different kinds of trees, I find it a little bit tedious to do the spacing manually every time. I don't know if doing it in tikz-qtree would help, but I still appreciate you answering my question! – Oow Feb 14 '14 at 21:05
  • @Oow You're welcome. My solution is based on the recommendations on the LaTeX for Logicians website. I kind of like the fact that it is possible to use this method without solving the problem in advance (i.e. you don't have to know what the tree will look like). But I think it just depends on (a) where you start and (b) what kinds of modifications you expect to need (and so what you will need to adjust manually). This solution worked quite well for me with incremental overlays in beamer. I expect you could do the same with Adam's solution (which would never have occurred to me). – cfr Feb 14 '14 at 21:42
  • @Oow In case you are still doing these, see my updated answer below using prooftrees. (Doesn't require manual spacing or separate trees for the numbers etc. - indeed, the numbering is automatic.) – cfr Mar 22 '16 at 4:10
  • I don't actually do these anymore, as this was for a single course in modal logic. However I did try out your example and I agree; it definitely is much easier and the code looks cleaner in my taste. I will switch to your answer for this question. Thank you very much! – Oow Mar 23 '16 at 14:45
  • @Oow Thanks. Interesting. I didn't realise these were used in modal logic - I've only ever come across them in use for teaching 'baby' logic. (Not that it is very babyish, but still.) Maybe the package will get more use than I thought ;). – cfr Mar 23 '16 at 17:24
5

If you're open to a different approach, I would actually go about this by \usetikzlibrary{matrix} instead. I think this solution might be preferable to @cfr's solution, as one does not have to manually adjust the spacing for this solution.

That is, one can specify the matrix options of column sep and row sep globally in order to get some default spacing that one wants for all rows and columns. Yet, at the same time, if one wants to manipulate some of the spacing individually, one can do so by, for example, using the optional argument to \\, as I have done in line 8 of the matrix in order to provide more separation for the branching part of the 'tree'.

\documentclass{article}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{amssymb}
\newcommand*{\tnot}{\ensuremath{\mathord{\sim}}} % following @cfr's suggestion

\usepackage{tikz}
\usetikzlibrary{matrix}

\begin{document}

\begin{tikzpicture}
\matrix (m) [matrix of nodes, row sep=0.2em,
column sep=0.1em, text height=1.5ex, text depth=0.25ex]
{
1   &                                       &   $(\exists x) Fx \supset (\forall x) Fx\ \checkmark$             &                               & SM \\ 
2   &                                       &   $\tnot (\forall x) (Fx \subset (\forall y) Fy)\  \checkmark$    &                               & SM \\ 
3   &                                       &   $(\exists x) \tnot (Fx \subset (\forall y) Fy)\ \checkmark$     &                               & 2 $\tnot\forall$D \\ 
4   &                                       &   $\tnot (Fa \subset (\forall y) Fy)\ \checkmark$                 &                               & 3 $\exists$E \\ 
5   &                                       &   $Fa$                                                            &                               & 4 $\tnot\supset$D \\ 
6   &                                       &   $\tnot (\forall y) Fy\ \checkmark$                              &                               & 4 $\tnot\supset$D \\ 
7   &                                       &   $(\exists y) \tnot Fy\ \checkmark$                              &                               & 6 $\tnot\forall$D \\
8   &                                       &   $\tnot Fb$                                                      &                               & 7 $\exists$D \\[2em] % here I've added some space so the tree can branch
9   &   $\tnot (\exists x) Fx\ \checkmark$  &                                                                   & $(\forall x) Fx\ \checkmark$  & 1 $\supset$D \\
10  &   $(\forall x) \tnot Fx\ \checkmark$  &                                                                   &                               & 9 $\tnot\exists$D \\
11  &   $\tnot Fa$                          &                                                                   &                               & 10 $\forall$D \\
12  &   $\otimes$                           &                                                                   & $Fb$                          & 9 $\forall$D \\
    &                                       &                                                                   & $\otimes$                     & \\
};

\path[-]    (m-8-3.south) edge (m-9-2.north)
            (m-8-3.south) edge (m-9-4.north)
            (m-9-4) edge (m-12-4);

\end{tikzpicture}

\end{document}

enter image description here

  • This approach seems very interesting. I'm gonna try this to my own trees. Thank you very much! – Oow Feb 14 '14 at 21:01
  • @Oow you're welcome! Glad it helped. – Adam Liter Feb 14 '14 at 21:05
  • 1
    I like this solution although I would personally find it less convenient. (The manual spacing is a pain but I don't need to know the shape of the tree before I start i.e. I can solve the problem as I typeset. Also, you can adapt mine for beamer to get the steps shown incrementally in a fairly natural way.) But it would be nice to have a package which was really designed for this - indeed, it would be nice to have more packages for logic generally. (The spacing of the ~ is all wrong, for example. This can be adjusted but typesetting logic always feels like a hack!) – cfr Feb 14 '14 at 21:50
  • @cfr Agreed! :) – Adam Liter Feb 14 '14 at 21:51
  • @cfr Excuse me for my ignorance, but what do you mean by beamer? What kind of feature is that, and how would you use it? (I guess I'm going off-topic now, not sure how the rules are here on this site) – Oow Feb 14 '14 at 22:22
3

Just for fun I wanted to try with forest and with all columns being branches from the same tree.

The main problem was how to adjust horizontal alignment between columns. forest documentation mention (page 17) that when text includes parenthesis, the alignment will look strange because it's a very special situation. But, as usual, it also provides a solution consisting in defining a new \forestStandardNode.

So, a possible solution with forest could be:

\documentclass[tikz,border=2mm]{standalone}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[norsk]{babel}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{mathtools}
\usepackage{qtree}
\usepackage{forest}

\newcommand*{\tnot}{\ensuremath{\mathord{\sim}}} % following @cfr's suggestion

\begin{document}
\forestStandardNode[(dj)]
{%
\forestOve{\csname forest@id@of@standard node\endcsname}{content},%
\the\ht\strutbox,\the\pgflinewidth,%
\pgfkeysvalueof{/pgf/inner ysep},\pgfkeysvalueof{/pgf/outer ysep},%
\pgfkeysvalueof{/pgf/inner xsep},\pgfkeysvalueof{/pgf/outer xsep}%
}
{
l sep={\the\ht\strutbox+\pgfkeysvalueof{/pgf/inner ysep}},
l={l_sep()+abs(max_y()-min_y())+2*\pgfkeysvalueof{/pgf/outer ysep}},
s sep={2*\pgfkeysvalueof{/pgf/inner xsep}}
}
{l sep,l,s sep}

\begin{forest}
[,phantom, for descendants={no edge}
    [1, [2[3[4[5[6[7[8[9[10[11[12]]]]]]]]]]]]
    [$(\exists x) Fx \supset (\forall x) Fx\ \checkmark$
        [$\tnot (\forall x) (Fx \subset (\forall y) Fy)\  \checkmark$
            [$(\exists x) \tnot (Fx \subset (\forall y) Fy)\ \checkmark$
                [$\tnot (Fa \subset (\forall y) Fy)\ \checkmark$
                    [$Fa$
                        [$\tnot (\forall y) Fy\ \checkmark$                             
                            [$(\exists y) \tnot Fy\ \checkmark$
                                [$\tnot Fb$
                                    [$\tnot (\exists x) Fx\ \checkmark$, edge={draw}
                                        [$(\forall x) \tnot Fx\ \checkmark$                                                    
                                            [$\tnot Fa$
                                                [$\otimes$, tier=otimes]]]]
                                    [$(\forall x) Fx\ \checkmark$, edge={draw}
                                        [$Fb$,tier=otimes, edge={draw}
                                                        [$\otimes$]]]]]]]]]]]
    [SM [SM[2 $\tnot\forall$D[3 $\exists$E[4 $\tnot\supset$D[6 $\tnot\forall$D
       [7 $\exists$D[1 $\supset$D[9 $\tnot\exists$D[10 $\forall$D
       [9 $\forall$D]]]]]]]]]]]
]
\end{forest}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.