1

I am looking to replicate in TeX this tree diagram I made in PowerPoint. What makes it harder than you basic tree is the multiline labels at terminal nodes, the Xs on some terminal node labels and the "R.1/R.2" labels between branches.

It would really bother me to keep the PowerPoint version, but also to spend 1 month trying to figure it out.

Grateful for any help.

diagram of interest

2 Answers 2

3

This is simple to do with forest. There are plenty of similar trees on the site. I've chosen to add the crosses separately rather than adding the decoration to the forest nodes directly, because this better allows to control their size.

\documentclass{article}
\usepackage[linguistics]{forest}
\usetikzlibrary{decorations,positioning}
\begin{document}
\begin{forest}for tree={l sep'=1cm,s sep'=1cm}
[Undertaking\\ART,name=Art
    [Unsuccesful,name=U
        [Spontaneous\\Conception\\(Only SC child)\\{[A]} ]
        [No Spontaneous\\Conception\\(no conception)\\{[B]},name=B]
    ]
    [Successful
        [Spontaneous\\Conception\\(very rare)\\{[C]},name=C ]
        [No Spontaneous\\Conception\\(only ART child)\\{[D]}]
    ]
]
\node[red,draw,cross out,minimum size=1cm] at (B) {};
\node[red,draw,cross out,minimum size=1cm] at (C) {};
\node[below=1cm of Art] {R.1};
\node[below=.5cm of U] {R.2};
\end{forest}
\end{document}

output of code

If you don't like the joined branches that the [linguistics] library uses, don't load it and you'll get branches that aren't joined. In this case you need to add the align=center specification to the tree to allow linebreaks in the nodes.

\documentclass{article}
\usepackage[]{forest}
\usetikzlibrary{decorations,positioning}
\begin{document}
\begin{forest}for tree={l sep'=1cm,s sep'=1cm,align=center}
[Undertaking\\ART,name=Art
    [Unsuccesful,name=U
        [Spontaneous\\Conception\\(Only SC child)\\{[A]} ]
        [No Spontaneous\\Conception\\(no conception)\\{[B]},name=B]
    ]
    [Successful
        [Spontaneous\\Conception\\(very rare)\\{[C]},name=C]
        [No Spontaneous\\Conception\\(only ART child)\\{[D]}]
    ]
]
\node[red,draw,cross out,minimum size=1cm] at (B) {};
\node[red,draw,cross out,minimum size=1cm] at (C) {};
\node[below=1cm of Art] {R.1};
\node[below=.5cm of U] {R.2};
\end{forest}
\end{document}

output without linguistics library

2
  • This is spot on! Publishing also my own answer, built with the help of yours.
    – Marti
    Commented Sep 29, 2023 at 2:48
  • l sep'=1cm, s sep'=1cm is quicker.
    – cfr
    Commented Sep 29, 2023 at 4:10
0

Here is my own answer, found with the help of @Alan Munn:

\documentclass{article}

    \usepackage{tikz}
      \usetikzlibrary{positioning}
      \usetikzlibrary{calc}
      \usetikzlibrary{trees}

\begin{document}

\begin{tikzpicture}[
    level 1/.style = {black, sibling distance = 8cm},
    level 2/.style = {black, sibling distance = 4cm},
    level distance = 3cm, % Increase the level distance  
  ]

  \node [align=center] (undertaking) {Undertaking \\ ART cycle}
  child {node [align=center] (succ) {Unsuccessful}
  child {node (A) [align=center] {Spontaneous \\ Conception \\ {\small (only SC child)} \\ {[A]}}}
  child {node (B) [align=center] {No Spontaneous \\ Conception \\ {\small (no conception)} \\ {[B]}}}
  }
  child {node (unsucc) {Successful}
  child {node (C) [align=center] {Spontaneous \\ Conception \\ {\small (only SC child)} \\ {[C]}}}
  child {node (D) [align=center] {No Spontaneous \\ Conception \\ {\small (no conception)} \\ {[D]}}}
  };

  \node [align=center, below=1cm of undertaking] {\bfseries R.1};
  \node [align=center, below=1cm of succ] {\bfseries R.2};
  \node [align=center, below=1cm of unsucc] {\bfseries R.2};
  \node[red,draw,cross out,minimum size=1.5cm] at (B) {};
  \node[red,draw,cross out,minimum size=1.5cm] at (C) {};
\end{tikzpicture}

\end{document}

enter image description here

4
  • 1
    As you can see, the forest syntax is much simpler than the base TikZ tree methods.
    – Alan Munn
    Commented Sep 29, 2023 at 3:12
  • 100%, although I am not a big fan of those branches :D
    – Marti
    Commented Sep 29, 2023 at 4:37
  • 1
    That's a function of the linguistics library. If you don't like them you can get branches like the one in your tree. I've updated my answer.
    – Alan Munn
    Commented Sep 29, 2023 at 4:43
  • wonderful, thanks a lot!
    – Marti
    Commented Sep 29, 2023 at 4:45

You must log in to answer this question.

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