# Diagramming multiple inheritance with trees in LaTeX

#1

Does anyone have experience making trees that show multiple inheritance in LaTeX? Something along these lines:

I’m not sure how they got the converging lines that lead to ‘Su-Wh-Rel’ and ‘That-Rel.’ Anyone done this before?

Thanks!

#2

You can use the forest package for trees. Since it’s Tikz-based, you can just \draw the other lines later. Here’s what I do for the variable hierarchy:

% preamble:
\usepackage{forest}
\newcommand\nd[1]{\texttt{#1}}
% body
\begin{figure}[htb]
\centering\small
\begin{forest}
[\nd{u}
[\nd{i},name=i,calign=last
[\nd{e}]
[,phantom]
]
[,phantom
[\nd{x},name=x]
]
[\nd{p},name=p,calign=first
[,phantom]
[\nd{h}]
]
]
\draw (p) -- (x) (i) -- (x);
\end{forest}
\caption{Variable hierarchy}
\label{fig:var-hier}
\end{figure}


Resulting in the following:

The [,phantom] nodes are just empty nodes to help with spacing. If I remove them (and make the x node a child of the i node) it looks like this:

#3

Thanks! Forest looks like a much better package to use than what I was doing.

#4

Does anyone know how to connect the lines when using \draw, so that it looks like the first image?

#5

If you use (nodename.north) and (nodename.south), that will draw lines from the very top and bottom, respectively. For example:

\draw (p.south) -- (x.north);


I’ve never used the forest package, so I don’t know how to make its lines behave similarly. When I’ve made this kind of hierarchy, I’ve done it directly in TikZ, using the [on grid] setting and placing nodes relative to each other.

#6

Thanks, Guy! Here is a full working example for those using forest:

\usepackage{forest}
\forestset{
joinedges/.style={for tree={parent anchor=south, child anchor=north}},
agree/.style={tikz={\draw[-,dotted] () to[out=south,in=south] node[below]{} (#1);},}
}
\begin{forest}
joinedges
[A [B [C] [D] [E, name=E]] [F, name=F [G] [H]]]
\draw (F.south) -- (E.north);
\end{forest}


This yields:

A phantom node like Mike suggests would probably help with the alignment, but in my case, this looked fine once I wrote out type names.