6

I want to set the following picture:

enter image description here

The following forestcode almost does it:

\documentclass{article}

\usepackage{forest}


\begin{document}

\begin{forest}
for tree={fit=band,parent anchor=south,child anchor=north}
[ForceP
        []
        [Force$'$
                [Force$^0$]
                [TopP
                        []
                        [Top$'$
                                [Top$^0$]
                                [FocP
                                        []
                                        [Foc$'$
                                                [Foc$^0$]
                                                [TopP
                                                        []
                                                        [Top$'$
                                                                [Top$^0$]
                                                                [FinP
                                                                        []
                                                                        [Fin$'$
                                                                                [Fin$^0$]
                                                                                [IP/AgrSP]]]]]]]]]]]
\end{forest}


\end{document}

However, the arcs that go towards the left do not have the right angle:

enter image description here

Now, the question is: Do I have to add \struts to all empty nodes or is there a nicer way to say that the empty nodes have the same height as their sisters to the right?

egreg
  • 1,121,712
Stefan Müller
  • 6,901
  • 3
  • 29
  • 61
  • I don't get that output either, as @egreg said. Part of the code is missing? Or this is a different version? – cfr Apr 23 '15 at 13:06
  • I added the options parent anchor=south,child anchor=north so as to reproduce exactly the output in the picture. – egreg Apr 23 '15 at 13:13
  • @egreg This will mess up Harish Kumar's answer! – cfr Apr 23 '15 at 13:40

2 Answers2

6

Here's an alternative method which looks better to me when I also add the sn edges style to the tree. Rather than use the nice empty nodes trick of setting shape to coordinate, this creates phantom content for the empty nodes (just an X) and uses a standard text height for all nodes in the tree to keep things aligned.

\documentclass[tikz,border=5pt]{standalone}
\usepackage{forest,calc}

\begin{document}
\newlength\mytextheight
\settototalheight{\mytextheight}{XpX$^0$X$'$}
\begin{forest}
  delay={
    where content={}{
      content={\phantom{X}}
    }{},
  },
  for tree={
    text height=\mytextheight,
    fit=band,
    parent anchor=south,
    child anchor=north,
  }
  [ForceP
    []
    [Force$'$
      [Force$^0$]
      [TopP
        []
        [Top$'$
          [Top$^0$]
          [FocP
            []
            [Foc$'$
              [Foc$^0$]
              [TopP
                []
                [Top$'$
                  [Top$^0$]
                  [FinP
                    []
                    [Fin$'$
                      [Fin$^0$]
                      [IP/AgrSP]
                    ]
                  ]
                ]
              ]
            ]
          ]
        ]
      ]
    ]
  ]
\end{forest}
\end{document}

nicer empty nodes?

cfr
  • 198,882
3

You can define an nice empty nodes style as in page 52 of the forest manual.

\documentclass{article}

\usepackage{forest}
\forestset{
nice empty nodes/.style={
for tree={calign=fixed edge angles},
delay={where content={}{for parent={for children={anchor=north}}}{}}
}}

\begin{document}

\begin{forest}
for tree={fit=band}
[ForceP, nice empty nodes
        []
        [Force$'$
                [Force$^0$]
                [TopP
                        []
                        [Top$'$
                                [Top$^0$]
                                [FocP
                                        []
                                        [Foc$'$
                                                [Foc$^0$]
                                                [TopP
                                                        []
                                                        [Top$'$
                                                                [Top$^0$]
                                                                [FinP
                                                                        []
                                                                        [Fin$'$
                                                                                [Fin$^0$]
                                                                                [IP/AgrSP]]]]]]]]]]]
\end{forest}


\end{document}

enter image description here

  • 1
    You can improve the appearance of calign=fixed edge angles by tweaking the angle of the branches (e.g., calign angle=60, calign angle=45, etc.). This will need to be balanced against horizontal space constraints for the tree, especially if used with fit=band. – Jason Zentz Apr 23 '15 at 13:53
  • 1
    The definition of nice empty nodes in the forest manual includes shape=coordinate, which is necessary when the empty nodes are along the spine of the tree. However, there is a bug in pgf that sometimes throws an error when you use sn edges with that version of nice empty nodes. See this question and the comments under it for a workaround. If you run into the division by 0 error, you can tweak the sep values of a rectangle node for empty nodes instead of using a coordinate node. – Jason Zentz Apr 23 '15 at 14:12