5

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.

1
  • 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, 2011 at 1:10

3 Answers 3

9

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}
2
  • 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, 2011 at 22:36
  • 2
    @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, 2011 at 22:47
2

With forest you can generally do this quite nicely using the nice empty nodes style (page 52, example 81). However, sometimes it doesn't quite work that simply. Your tree is one such example. Nonetheless, it is possible to get the tree very nearly perfect to the point that I challenge anybody to know that the tree does not use the unadulterated form of nice empty nodes without looking at the code, magnifying hugely or using nefarious subterfuge of other kinds.

The advantage of this is that the tree can be typeset using the very concise bracket syntax.

Here's the result (ignore the fonts - I don't know what is used in the question and didn't try to emulate them):

<code>forest</code> quite nice empty nodes

I'm going to call this quite nice empty nodes, I think, in the British sense of 'quite' ;).

Here's the code:

\documentclass[10pt,tikz,border=5pt]{standalone}
\usepackage{forest}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\begin{document}
\begin{forest}
  for tree={
    calign=fixed edge angles,
    parent anchor=south,
  },
  before typesetting nodes={% page 52: example (81)
    where content={}{% shape=coordinate gives an error if used here but this is *almost* right - it just leaves a little, tiny gap
      text width=.001pt,
      inner sep=0pt,
      before drawing tree={% here we make sure that the tiny gap disappears so only the size is not quite dimensionless
        shape=coordinate,
        typeset node,
      },
      for parent={
        for children={
          anchor=north,
        }
      }
    }{}
  }
  [DP
    [Qfr]
    [
      [D]
      [$\phi$P
        [CP]
        [
          [Nml]
          [
            [$\phi$]
            [NP]
          ]
        ]
      ]
    ]
  ]
\end{forest}
\end{document}
1

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

3
  • 2
    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, 2011 at 3:56
  • @Alan, ouch, you're right. :-[
    – Aaron
    Nov 17, 2011 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, 2011 at 21:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .