2

I'd like to use the tikz package to draw a tree diagram (see my code until now below). My issue is that the nodes all are restricted to their own matrix column, so my diagram becomes too broad to fit on a single page and does not look nice in general. Instead, I'd like the nodes to overlap, e.g. the node on the uppermost level of my diagram should not only be restricted to the 4th column, but also occupy parts of the 3rd and the 5th column. Any ideas how to achieve that?

Just for the sake of clarity, here an image I found online of a tree diagram with overlapping nodes: http://thepeakperformancecenter.com/wp-content/uploads/2017/03/Tree-Diagram.jpg[][1]

And here the code I wrote so far:

\begin{tikzpicture}
  \matrix (m) [
    matrix of nodes,
    nodes={draw},
    column sep=1mm,
    row sep=12mm,
  ] {
          &   &      & Does the wave function collapse? & & &  \\
     &    Is the collapse spontaneous or produced externally? &   & &      & Are there hidden variables? & \\
 Von Neumann & & GRW   &  & Many Worlds & & Bohm \\
  };
  \begin{scope}[
    font=\footnotesize,
    inner sep=.25em,
    line cap=round,
  ]
    \newcommand*{\LINE}[4][.5]{%
      \path (m-#2) -- node[pos=#1] (tmp) {$#4$} (m-#3);
      \draw (m-#2) -- (tmp) -- (m-#3);
    }
      \LINE      {1-4}{2-2}{Yes}
      \LINE[.7]  {1-4}{2-6}{No}
      \LINE{2-2} {3-1}{External}
      \LINE      {2-2}{3-3}{Spontaneous}
      \LINE      {2-6}{3-5}{Yes}
      \LINE      {2-6}{3-7}{No}

  \end{scope}
\end{tikzpicture}
  • 1
    Welcome to TeX SX! The link answers ‘page not found’. Can't you add the image to your post? – Bernard Jul 18 at 10:28
4

I'm guessing that you like to have something like this:

enter image description here

This tree is drawn by use of the forest package (dedicated to drawing tree diagrams). I also broke long text in one node into two lines:

\documentclass[margin=3mm]{standalone}
\usepackage{forest}

\begin{document}
\begin{forest}
    for tree = {draw,
                align=center,
                anchor=north,
                s sep=5mm,  % horizontal distance between nodes
                l sep=7mm,  % vertical distance between nodes
                tier/.option=level,
                EL/.style = {edge label={node[midway, fill=white, inner sep=2pt,
                                              font=\footnotesize\itshape, anchor=center,
                                              text depth=0.3ex]{#1}}, 
                            }% edge labels style
                }
  %
[Does the wave function collapse?
    [Is the collapse spontaneous\\ or produced externally?,EL=Yes
        [Von Neumann,EL=External]
        [GRW,EL=Spotaneous]
    ]
    [Are there hidden variables?,EL=No
        [Many Worlds,EL=Yes]
        [Bohm,EL=No]
    ]
]
\end{forest}
\end{document}    

edit: ups, I forgot on edge labels. Now they are added

edit (2): added missed \documentclass, improved edge labels positioning

  • Yes that's exactly what I was looking for, thanks a lot! – Surstroemmingpirat Jul 20 at 15:52

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.