3

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 }{ ... }
}
Amadan
  • 175
  • 1
    create a complete example, then I'll have a look –  Nov 01 '11 at 09: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 01 '11 at 13:24
  • no, a complete example starts with \documentclass{..} –  Nov 01 '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 01 '11 at 18:21
  • No MWE after nearly a month => 'not a real question' – Joseph Wright Nov 30 '11 at 12:52
  • 1
    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

2 Answers2

5

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}
Jake
  • 232,450
  • 3
    that is exactly what people like who didn't provide a minimal example: that others do the work for them ... –  Nov 01 '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 01 '11 at 13:28
4

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.

screenshot

\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}
cmhughes
  • 100,947
  • you can work with treesep and thistreesep to get a better view –  Nov 01 '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 01 '11 at 17:57
  • 2
    @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 01 '11 at 18:33