# Getting straight lines with empty nodes in forest

I have the following trees and I want the lines parallel to the red lines to be straight lines. Right now they are two separate lines but it should be one straight line. Is this possible?

\documentclass{article}

\usepackage{forest}
\useforestlibrary{linguistics}
\forestapplylibrarydefaults{linguistics}

% specification for all trees, "default preamble" appends to existing specification.
% The version with apostrophe replaces it.
\forestset{default preamble'={
for tree={align=center,parent anchor=south, child anchor=north,anchor=north,base=bottom},
% This would align trees to the baseline. We do not want this for TAG
% where several trees have to be aligned with respect to their center.
%    before drawing tree={
%      sort by=y,
%      for min={tree}{baseline}
%    }
}}

\forestset{
declare dimen={child anchor yshift}{0pt},
adjust childrens child anchors/.style={
if n children>=2{
before packing={
tempdima/.max={max_y}{children},
for children={
child anchor yshift=tempdima()-max_y()
},
}
}{}
},
default preamble={
for tree={
edge path'={(!u.parent anchor)--([yshift=\forestoption{child anchor yshift}].child anchor)},
adjust childrens child anchors
}
},
}

\forestset{
empty nodes/.style={
delay={where content={}{shape=coordinate,for siblings={anchor=north}}{}}
},
sm edges without translation/.style={for tree={parent anchor=south, child anchor=north,base=bottom},
where n children=0{tier=word}{}
}
}

\begin{document}

\begin{forest}
empty nodes
[{}
[X \\ {[\textit{u}F]}]
[{}
[Y \\ {[F v]}, roof]]]
\end{forest}

\begin{forest}
sm edges without translation, empty nodes
[{}
[X \\ {[\textit{u}F v]}]
[{}
[Y \\ {[F v]}, roof]]]
\end{forest}

\end{document}


Edit: The problem seems to be related to the roof.

\documentclass{article}

\usepackage{forest}
\useforestlibrary{linguistics}
\forestapplylibrarydefaults{linguistics}

\begin{document}

\begin{forest}
nice empty nodes
[{}
[X \\ {[\textit{u}F]}]
[{}
[Y \\ {[F v]}, roof]]]
\end{forest}
\hspace{2cm}
\begin{forest}
nice empty nodes
[{}
[X \\ {[\textit{u}F]}]
[{}
[Y]
[Z]]]
\end{forest}

\end{document}

• There are quite a few solutions on the site, all of which are compromises. See Forest for linguistics - proportional alignment like in qtree or A nice empty node with nice nodes in forest? or Tree in forest using the style fairly nice empty nodes on. Any of these are effectively duplicates of your question. See also nice empty nodes broken by forest 2.0? – Alan Munn Aug 31 '18 at 15:07
• I tried everything and it works but not for my example. The problem is the roof. It seems to break things. If I replace [Y ... by [Y] [Z] the lines are ok. – Stefan Müller Aug 31 '18 at 15:45
• Ok. It would he helpful to show the comparison and make it clear that the issue is the roof. – Alan Munn Aug 31 '18 at 15:51
• I haven't looked at Forest's code for this, but I think it would be easiest not to use roof which, I guess (?), may not be designed for this. Are roofs usually expected to line up? @AlanMunn ? – cfr Sep 2 '18 at 0:28
• In one tree, Y has a sibling. In the other, it doesn't. The placement of Y is identical in each case. You don't preserve the angle of the edge when you have an only child, irrespective of whether you use roof or not. roof is just irrelevant as far as I can see. @AlanMunn – cfr Sep 2 '18 at 1:16

As @cfr notes in the comments, path that you want to modify with fixed edge angles is not part of the roof.

The size of the roof is determined by the size of its contents.

So there are two possible solutions I think.

One is to draw the roof manually with phantom nodes. In this code I've made a macro to wrap features in [...] otherwise forest gets confused by the brackets in the node drawn under the roof.

The other possibility (which is probably easier) is to put the contents of the roof inside a fixed size box using \makebox. I've used 1.5em as the width just by estimation.

\documentclass{article}

\usepackage[linguistics]{forest}

\begin{document}
\newcommand{\brk}[1]{[#1]}

\begin{forest}
nice empty nodes
[
[X \\ {\brk{\textit{u}F}}]
[
[\phantom{Y},name=Y]
[\phantom{Z},name=Z]]]
\draw (Y.north)  -- (Z.north) node [midway,below,align=center] {Y\\{\brk{F v}}};
\end{forest}

\begin{forest}
nice empty nodes
[
[X \\ {[\textit{u}F]}]
[
[Y \\ {\makebox[1.5em]{[F v]}}, roof]]]
\end{forest}

\end{document}


• Thanks! I used ~ as a less elegant variant of the makebox. Don't tell anybody. – Stefan Müller Sep 25 '18 at 9:11