Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I’m using TikZ to draw linguistic syntax trees where some nodes have textual labels and some nodes don’t. I’d like the branch from a labelless node to continue at the same angle into the right hand daughter (or alternatively into the left hand daughter) as the branch that went to the node, so that the two branches form a visually continuous line at the same angle. I worked out how to do so for one labelless node using a kluge of lots of anchor specifications for each child. This fails to work for more than one labelless node and it’s a really messy method anyway. There must be a better way to do this but I haven’t figured it out. Any suggestions? (I’m using XeTeX but this shouldn’t matter I think.)

\begin{tikzpicture}[level distance=2em,
            sibling distance=4em,
            parent anchor=south,
            child anchor=north,
            anchor=north,
            align=center,
%           every node/.style={draw}
            ]
\node{DP}
    child {node {Qfr}}
    child {node (dbar) {}
        child[parent anchor=north, anchor=base] {node {D}}
        child[parent anchor=north, anchor=base] {node {ΦP}
            child[parent anchor=south, anchor=north] {node {CP}}
            child[parent anchor=south, anchor=north] {node (phibar) {}
                child[parent anchor=north, anchor=base] {node {Nml}}
                child[parent anchor=north, anchor=south] {node (phibar2) {}
                    child[parent anchor=north, anchor=base] {node {Φ}}
                    child[parent anchor=north, anchor=base] {node {NP}}}}}};
\end{tikzpicture}

Output of code above.

share|improve this question
    
The branch above the bottommost, joining “Φ” and “NP”, is the problem in the screenshot above. The parent branch should end at the same y-value as the one that ends at the “Nml” node, but instead it ends up a bit lower and hence the angle is not the same as the others. –  James C. Nov 17 '11 at 1:10
add comment

2 Answers

up vote 6 down vote accepted

Instead of using empty nodes with {}, I would suggest you leave them out completely. To get the vertical spacing right, you can let all edges start at the parent anchor=center, which will coincide with the north anchor for the empty branches (so you get a continuous line) but be in the middle of the text nodes. To move the lines out of the text, you can specify a text depth for all the nodes (which will not have an influence on the empty branches).

\begin{document}
\begin{tikzpicture}[
    level distance=2em,
    sibling distance=4em,
    anchor=north,
    parent anchor=center,
    child anchor=north,
    text depth=2.5ex % Use this to define the vertical space between the entering and exiting edge of a text node
]
\node{DP}
    child {node {Qfr}}
    child {
        child {node {D}}
        child {node {$\Phi$P}
            child {node {CP}}
            child {
                child {node {Nml}}
                child {
                    child {node {$\Phi$}}
                    child {node {NP}}}}}};
\end{tikzpicture}

\end{document}
share|improve this answer
    
How will I reference the branching points (say for pointing an arrow at them) without having a node there? Is there a way to place a node with no height and no width? –  James C. Nov 18 '11 at 22:36
1  
@JamesC.: Yeah, you can just say coordinate (<name>) (or equivalently node [coordinate, name=<name>] {}). That's a special node shape of zero height and width and without text, with only a center anchor. –  Jake Nov 18 '11 at 22:47
add comment

Just use the tikz-qtree package, which in addition to solving your problem lets you input the trees in a much less verbose way. The examples in the manual have all their nodes labeled, but the package does the right thing if you don't label a node. Here's a (modified by randomly deleting a couple labels) example from the manual, and the result:

\Tree [.S [.NP [.Det the ] [.N cat ] ] [ [.V sat ]
[.PP [.P on ] [ [.Det the ] [.N mat ] ] ] ] ]

output of tikz-qtree

share|improve this answer
1  
Unfortunately you got lucky with your example: Try James' example: \Tree [.DP [.Qfr ] [ [.D ] [.ΦP [.CP ] [ [.Numl ] [ [.Φ ] [.NP ]]]]]]] and you can replicate his problem even with tikz-qtree. –  Alan Munn Nov 17 '11 at 3:56
    
@Alan, ouch, you're right. :-[ –  Aaron Nov 17 '11 at 7:25
    
tikz-qtree, as your example shows, adds a unary branch between the leaf nodes and the elements beneath them. I don’t like that style for various reasons, so I’ve been rolling my own trees instead. –  James C. Nov 18 '11 at 21:10
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.