12

The qtree package seems to facilitate the drawing of simple trees only. Is there a way to incorporate:

  1. Multiple roots &
  2. Nodes with multiple parents

in a tree in LaTeX?

  • 1
    Such objects aren't really trees. :) The tikz-qtree package provides more capabilities to combine trees because it is based on TikZ and has the full power of that package behind it. But out of the box, no tree drawing package can do what you want. Qrrbrbirlbel's answer to this question: How to reflect duplicating a tree horizontally? might provide the beginnings of a more general way to do some of this. See also Graph-like structures with Qtree. – Alan Munn May 13 '13 at 20:29
  • @AlanMunn: Thank you. The information was quite helpful. You might want to shift your reply from the comment section to the answer section, so that I can acknowledge it as the accepted answer. :) – Chatterjee May 13 '13 at 20:46
  • Thanks. I'll wait a bit, since the answer is essentially negative. There are some very clever TikZ people here who might have some ideas on solutions, but if nothing shows up in a day I'll convert my comment to an answer. – Alan Munn May 13 '13 at 20:49
16

Multi-dominance "trees" are not really trees, but graphs, and the standard tree drawing packages are really not designed to handle them. Depending on the complexity of the tree, it's possible to draw these trees, however, but it requires some manual intervention. I would use one of the TikZ based tree drawing packages for this rather than qtree. The two best such packages are tikz-qtree and very powerful forest package. The general method for achieving multi-dominance is the same: you draw an empty edge and node, and then manually draw the extra branch to the relevant node that has multiple parents.

Using tikz-qtree

\documentclass{article}
\usepackage{tikz-qtree,tikz-qtree-compat}


\begin{document}
% Some multi-dominance structures using qtree and forest
% We fake the multi-dominance with an empty edge and node and then
% a regular tikz \draw between the node and its extra parent
\begin{tikzpicture}[sibling distance=.25cm]
\Tree [.Y
        [.Z ]
        [.\node (X) {X}; 
           [.A [.B ] [.\node (C) {C}; ] ]
           [.\node (A2) {A};
             \edge[draw=none]; {} \edge; {B} ]]]] 
\draw (A2.south) -- (C.north);

\end{tikzpicture}
\end{document}

Using forest

\documentclass{article}
\usepackage{forest}
\forestset{qtree edges/.style={for tree=
    {parent anchor=south, child anchor=north}}}

\begin{document}
\begin{forest}
qtree edges
[Y
[Z ]
[X,name=X [A  [B ] [C, name=C ]]
   [A, name=A2  [, no edge ] [B ]]]]
\draw (A2.south) -- (C.north);
\end{forest}
\end{document}

output of code

Graphs with tkz-graph

For more complicated graphs, it's likely better to use a package designed specifically for graphs. Alain Matthes' tkz-graph package does just that. Here's a more complex example using that package. The documentation is in French, but there are plenty of examples to work from, and all the command syntax is English-based. Note also that tikz-qtree and tkz-graph cannot be used together because of command name clashes, but there is a patch to be found here:

How to use tkz-graph and tikz-qtree without conflict?.

\documentclass{article}
% a more complicated graph using tkz-graph
% depending on the actual graph this could be partially automated
% with tikz \for loops
\usepackage{tkz-graph}
\renewcommand*{\EdgeLineWidth}{0.15pt}

\begin{document}
\begin{tikzpicture}
\GraphInit[vstyle=Empty]
\Vertex{Y}
\Vertex[x=2,y=0]{Q}
\Vertex[x=1,y=-2]{X}
\Vertex[x=-1,y=-2]{Z}
\Vertex[x=3,y=-2]{R}
\Vertex[x=0,y=-3]{A}
\Vertex[x=2,y=-3]{B}
\Vertex[x=-1,y=-4]{C}
\Vertex[x=1,y=-4]{D}
\Vertex[x=3,y=-4]{E}
\Edges(Z,Y,X,Q,R) 
\Edges(A,X,B)
\Edges(C,A,D,B,E)

\end{tikzpicture}
\end{document}

enter image description here

  • I think you are drawing some edges repeatedly in the tkz-graph example. \Edges(Z,Y,X,Q,R) \Edges(A,X,B) \Edges(C,A,D,B,E) would just do. – Qrrbrbirlbel May 15 '13 at 0:17
  • @Qrrbrbirlbel Thanks for the correction. I'm not sure I quite get how the edge syntax works. – Alan Munn May 15 '13 at 0:31

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.