# Crossed hierarchy

I appreciate it if you let me know the most elegant way to draw a crossed hierarchy such as the followings:

    X
/\
Y  Z
/\/\
p q  t


q has two parents Y and Z.

-
You might find the question tex.stackexchange.com/q/75413/86 useful here, as it also is concerned with "multiple parents" in a tree. –  Loop Space Mar 18 '13 at 14:22
Welcome to TeX.sx! –  hpesoj626 Mar 18 '13 at 14:24
Another related recent question: Multi-rooted Tree-like Structures and Nodes with Multiple Parents in LaTeX –  Alan Munn May 30 '13 at 14:55

This is a hack because it uses the fact that the distance between nodes doesn't change from level to level and so by default branches will overlap:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node {X}
child {
node {Y}
child {
node {p}
}
child {
node {q}
}
}
child {
node {Z}
child {
node {\phantom{q}}
}
child {
node {t}
}
}
;
\end{tikzpicture}
\end{document}


The edge from Z to q is not really to the q but to an invisible q that sits on top of the first q.

A better way to do it is to name the nodes and draw the extra edge after the tree. This way if the q node moves the extra edge will still point to it. You can create a missing child node to keep the spacing as if there were an actual first child.

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[
level 1/.style={sibling distance=20mm},
level 2/.style={sibling distance=15mm}
]
\node {X}
child {
node {Y}
child {
node {p}
}
child {
node (q) {q}
}
}
child {
node (Z) {Z}
child[missing] {
node {q}
}
child {
node {t}
}
}
;
\draw (Z) -- (q);
\end{tikzpicture}
\end{document}


-
Thanks Matthew :) It worked out! –  Masood Mar 18 '13 at 15:46
@MasoodGhayoomi If this really helped you, apart from upvoting it, please accept this answer by clicking on the check mark. This marks your problem as solved. :) –  hpesoj626 Mar 19 '13 at 1:07