5

I created the following tree.

enter image description here

I would like the angle betwen lesbarkeit and lesbar and keit to be such that the edges are parallel to the ones of les and bar. I guess shifting lesbarkeit to the left would be sufficient. But this is font-dependent. Is there a better way to do this?

\documentclass{article}

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


\begin{document}


\begin{forest}
for tree={grow=north,where n children=0{tier=word}{},l sep+=\baselineskip} 
[lesbarkeit
  [keit]
  [lesbar
    [bar]
    [les]]]
\end{forest}
\end{document}
6

3 Answers 3

5

calign=fixed edge angles should ensure parallel edges because it should fix the angle between the direction of growth and each child's edge. There is a qualification here, which is that tier alignment will interfere but, nonetheless, the option should - at the very least - help.

If your tree grew downwards, that is exactly what it would do. The tier alignment would interfere, but the option would result in parallel edges. Since your tree grows upwards, however, the option does nothing of the kind. Indeed, investigation shows that the code does exactly the opposite of what it should do. For southwards growth, it correctly figures out that it needs to move the nodes closer together. For northwards growth, it incorrectly concludes it needs to move them further apart. Unsurprisingly, this doesn't help.

For this particular tree, I suggest the following strategy:

  • don't apply the linguistics library defaults - they interfere;
  • use a modification of the settings used for sn edges: set parent anchor=children, but don't use child anchor=parent;
  • instead use anchor=parent and add \strut to the nodes' content;
  • add calign=fixed edge angles and I set the angle also to 25;
  • don't add any additional l sep.

This looks, I think, all right, and I imagine it will look of-a-piece with other trees in the book.

parallel edges

This is not the 'correct' result. The solid grey lines show the path the edges should follow, but clearly do not.

An alternative workaround might be to do everything but drawing the tree southwards and then reverse all the y coordinates, but that could make a mess.

I'm not sure if I'm right, but it seems to me there is something awry in the implementation of fixed edge angles. Somehow, the option does not take the direction of the tree's growth into account properly when deciding what to adjust.

However, I'm not quite sure how all of the code works here. Even for the downwards direction, which mostly works, I get a dimension for the primary child's s of zero, so I'm not confident I understand what the code is supposed to do well enough to judge whether it is doing it or not.

\documentclass{standalone}

\usepackage{forest}
% \useforestlibrary{linguistics}
% \forestapplylibrarydefaults{linguistics}
\forestset{%
  test style/.style={%
    for tree={%
      grow=north,
      parent anchor=children,
      anchor=parent,
      calign=fixed edge angles,
      calign angle=25,
    },
    for leaves={tier=word},
    delay={%
      for tree={%
        content+={\strut},
      },
    },
  },
}
\newcommand \testcmd {%
  \foreach \i/\j in {%
    (!r.parent anchor)/red,%
    (!r1.child anchor)/blue,
    (!r2.child anchor)/green,
    (!r2.parent anchor)/magenta,
    (!r21.child anchor)/gray,
    (!r22.child anchor)/orange%
  } \path [fill=\j] \i circle (1pt);
  \foreach \i/\j/\k in {%
    (!r.parent anchor)/blue/65,%
    (!r2.parent anchor)/gray/115%
  }
  \draw [ultra thin,\j] \i -- ++(\k:30mm);
  \foreach \i in {%
    !r,!r2%
  } \draw [help lines,densely dashed] (\i) -- ++(90:40mm);
}
\begin{document}
\begin{forest}
  test style,
  [lesbarkeit
    [keit]
    [lesbar
      [bar]
      [les]
    ]
  ]
  \testcmd
\end{forest}
\end{document}

I suggest reporting this on GitHub, although there are a number of bugs outstanding for which fixes are known, so I'm not sure exactly what the status of the project is. However, it would be good to have a list of known issues, I think, so that they are all there when the author is able to find the time to attend to them.

See What causes calign=fixed edge angles to behave inconsistently when grow is not equal to 270? and the comment by forest's author on that question.

1
  • I should have said, it would look all right sans coloured dots and tracking lines. It obviously doesn't look good with them.
    – cfr
    Commented May 24 at 23:06
3

I suggest a different layout based on https://tex.stackexchange.com/a/148449/36296 which will avoid any problems with angles:

\documentclass{article}

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

\begin{document}

\begin{forest}
  for tree={
    grow=north,
    where n children=0{tier=word}{},
    l+=0.5cm, s sep=0.5cm,
    parent anchor=north, 
    child anchor=south,
    edge path={
      \noexpand\path[\forestoption{edge}](!u.parent anchor)--+(0,.4)-|(.child anchor)\forestoption{edge label};
    }
    % ^^^ from https://tex.stackexchange.com/a/148449/36296
  }
[lesbarkeit
  [keit]
  [lesbar
    [bar]
    [les]]]
\end{forest}
\end{document}

enter image description here

3
  • Thanks, but this does not fit the layout in the rest of the book. Commented May 24 at 16:20
  • 1
    @StefanMüller \begin{joke} chance the layout in the rest of the book \end{joke} Commented May 24 at 16:21
  • \if0 \begin{joke} \ldots \end{joke} \fi =:-) Commented May 24 at 16:26
3

Not perfect, but with the key calign=fixed angles the angles are more balanced (manual, section 3.7.2, Node position).

Example

\documentclass{article}

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

\begin{document}

\begin{forest}
  for tree={
    grow=north,
    where n children=0{tier=word}{},
    l sep+=\baselineskip,
    calign=fixed angles
  }
[lesbarkeit
  [keit]
  [lesbar
    [bar]
    [les]]]
\end{forest}
\end{document}

Example

If you want strictly the same angles, anchor the nodes at their center and shorten the edges

child anchor=center,
parent anchor=center,
edge={shorten <=1em,shorten >=1em},

Example:

\documentclass{article}

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

\begin{document}

\begin{forest}
  for tree={
    grow=north,
    calign=fixed angles,
    child anchor=center,
    parent anchor=center,
    edge={shorten <=1em,shorten >=1em},
    where n children=0{tier=word}{},
    l sep+=\baselineskip,
  }
[lesbarkeit
  [keit]
  [lesbar
    [bar]
    [les]]]
\end{forest}
\end{document}

Example 2

5
  • 1
    Ah! Now I understand why calign fixed angles did not work. I tried this before, but it was not exactly parallel. With your solution the edges do not touch. This would make this tree different from the rest of the book. Commented May 24 at 16:25
  • @StefanMüller Geometrically, you can't have at the same time regularly distributed nodes, touching edges with the same angle and a missing level.
    – jlab
    Commented May 24 at 16:34
  • 2
    Not sure what you mean by 'regularly distributed nodes', but there shouldn't be a problem having a common origin for the edges and parallel edges as far as I can tell. Admittedly, geometry wasn't my strong point at uni, but I don't think there's anything especially advanced here? (cc @StefanMüller)
    – cfr
    Commented May 24 at 22:17
  • @cfr I mean an equal horizontal distance between the nodes "leis", "bar" and "keit". There is a gap between the bottom and the top of "lefbar" that you haven't with a straight line from "lesbarkeit" to "keit".
    – jlab
    Commented May 24 at 22:23
  • Is that a requirement @StefanMüller? Maybe that's just obvious to linguists?
    – cfr
    Commented May 24 at 23:05

You must log in to answer this question.

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