# \pstree and crossed branches [closed]

Still a TeX newbie. I'm working with PSTricks pstree, and wish a tree whose branches cross:

        I
/ \
G   H
/ \ / \
F   /   E
/ \ / \
/   /   \
/   / \   \
A   B   C   D


If it's not clear from the ASCII picture,

F -> A C
G -> F D
H -> B E

A < B < C < D.


My usual tree code looks like:

\pstree{ I }{
\pstree{ G }{ ... }
\pstree{ H }{ ... }
}


## closed as not a real question by Marco Daniel, Joseph Wright♦Nov 30 '11 at 12:52

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. If this question can be reworded to fit the rules in the help center, please edit the question.

• create a complete example, then I'll have a look – user2478 Nov 1 '11 at 9:40
• That is the complete example, since I don't know what to write inside the pstree to allow for crossed branches. The dots would just be recursive repetition of what is already there, as I don't know how to make anything different. (With one exception: I messed up, and missed \TR{} around the node names.) And if you browse my stackoverflow account, you will see that I do not mind doing the work. I did not ask how to make this specific (and rather useless) tree, I asked what is the method by which I can make such a structure possible. – Amadan Nov 1 '11 at 13:24
• no, a complete example starts with \documentclass{..} – user2478 Nov 1 '11 at 17:46
• Oh. Look, I did say I was a TeX newbie. On StackOverflow, we actually frown on pasting too much code; posting full program listing is a serious no-no. I had no clue the rules are different here. – Amadan Nov 1 '11 at 18:21
• Hmm. I asked a question (very real to me), got an answer I found useful and marked it as such, and commented that it is exactly what I looked for. You want a MWE (I had to think about 5 minutes what the TLA might stand for), look at the answer that is selected. I could not have written it before I read how he did it. My paper now looks good because of cmhughes, to whom I am deeply grateful. The rest of you... with community that treats a self-admitted newbie like this, it is no surprise already prickly TeX does not get a bigger following. – Amadan Nov 30 '11 at 14:59

Here's a solution using pst-tree. You can tweak the parameters treesep and perhaps add a few more null nodes \Tn to get the spacing the way you want.

To get the lines to cross, I (perhaps cheated and) gave the relevant nodes names, and then connected them using an \ncline.

\documentclass{article}

\usepackage{pst-tree}

\begin{document}

\pstree[nodesep=3pt]{\TR{I}}{%
\pstree{\TR[name=G]{G}}%
{%
\pstree{\TR{F}}%
{\TR{A}\TR[name=B,edge=none]{B}\TR{C}\TR[name=D,edge=none]{D}}%
\Tn\Tn%
}%
\pstree{\TR[name=H]{H}}%
{\Tn\TR{E}}%
}% end the tree
\ncline[nodesep=3pt]{H}{B}
\ncline[nodesep=3pt]{G}{D}

\end{document}

• you can work with treesep and thistreesep to get a better view – user2478 Nov 1 '11 at 17:45
• @Herbert Thanks; I mentioned treesep in my introduction- I assume the OP will want to tweak these parameters on their own :) – cmhughes Nov 1 '11 at 17:57
• @cmhughes: Thank you, this looks to be exactly what I was looking for. Don't care if you call it cheating, it works. – Amadan Nov 1 '11 at 18:33

You could do this using TikZ. You can use [missing] to create "empty" branches that maintain the correct spacing but don't draw any objects. By doubling the level distance and sibling distance for the third level compared to the first two levels, the branches will cross while the angles of the branches are constant all throughout the tree (I'm not sure if that's what you actually wanted):

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[
level 3/.style={
level distance=30mm,
sibling distance=30mm
}
]
\node {I}
child {
node {G}
child {
node {F}
child {
node {A}
}
child {
node {C}
}
}
child {
child [missing]
child{
node {D}
}
}
}
child {
node {H}
child {
child {
node {B}
}
child [missing]
}
child {
node {E}
}
};
\end{tikzpicture}
\end{document}


Alternatively, you can just specify the level distance and sibling distance for individual child branches to get the desired placement:

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[
level distance=15mm,
sibling distance=15mm,
level 3/.style={
}
]
\node {I}
child {
node {G}
child {
node {F}
child {
node {A}
}
child {
node {C}
}
}
child [level distance=30mm, sibling distance=30mm] {
node {D}
}
}
child {
node {H}
child [level distance=30mm, sibling distance=45mm] {
node {B}
}
child {
node {E}
}
};
\end{tikzpicture}
\end{document}

• that is exactly what people like who didn't provide a minimal example: that others do the work for them ... – user2478 Nov 1 '11 at 10:09
• @Jake: Thank you, that is very helpful. I will try to do that, if no one suggests a \pstree method by tomorrow (I have never used tikz). I suppose messing with node's spacing is a good way to go - more flexible than the other, in case node names are too fat to render in fixed width. – Amadan Nov 1 '11 at 13:28