6

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?

enter image description here

\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. enter image description here

\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}
Stefan Müller
  • 6,901
  • 3
  • 29
  • 61
  • 1
    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 02 '18 at 00: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 02 '18 at 01:16
  • @cfr Since the roof it supposed to represent n unanalyzed children, it should be as wide as whatever you would imagine n to be. So if n = 2 then it could look like the tree containing Y and Z, which is what Stefan wants. Probably the simplest solution is to add some \phantom{X} to either side of the Y in the roof node. – Alan Munn Sep 02 '18 at 02:27
  • @AlanMunn Oh, I see. There's no correct way of drawing it, then. For n=2, there's no good way of doing it as Stefan wants as far as I can tell, so I think you should answer with that. fixed edge angles aligns the .child anchor and not .parent last, which is what Stefan wants it to do. Since that would not generally be what was wanted, I don't imagine this would be easy to implement at all. And it would be wrong for any other value of n anyway. At any rate, any non-fudgy solution can't possibly be worth it, I don't think, so a fudge is the best solution here. IMNSHO. – cfr Sep 02 '18 at 03:13
  • ^^ The above is SE's idiotic rendering of my markup. I thought I'd made a mistake, but, no, it is, of course, the site. @AlanMunn – cfr Sep 02 '18 at 03:15
  • OK. Thanks! I see. I guess the baseline of the roof is determined by what is under it. So it is {[F v]}. What I could play with to get the angle right is the hight of the triangle. – Stefan Müller Sep 02 '18 at 17:32
  • @StefanMüller The trouble is that you want to treat .parent last rather than .parent or .north as .child anchor, even though it isn't. The edge angles are equal. The path to the child anchor is perfectly straight. But that path is not part of the roof. – cfr Sep 02 '18 at 23:24

1 Answers1

1

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}

output of code

Alan Munn
  • 218,180