The qtree
package seems to facilitate the drawing of simple trees only. Is there a way to incorporate:
- Multiple roots &
- Nodes with multiple parents
in a tree in LaTeX?
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It only takes a minute to sign up.
Sign up to join this communityThe qtree
package seems to facilitate the drawing of simple trees only. Is there a way to incorporate:
in a tree in LaTeX?
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.
\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}
\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}
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}
tkz-graph
example. \Edges(Z,Y,X,Q,R) \Edges(A,X,B) \Edges(C,A,D,B,E)
would just do.
May 15, 2013 at 0:17
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.