2

Is there a way with the forest package to anchor the edge to the first line of a multi-line node?

enter image description here

In this example, I would like to have the middle horizontal edge point to the 123 of the multiline text node.

\documentclass[a4paper]{article}
\usepackage{geometry}% geometry or similar is needed for correct A4 layout
\usepackage[edges]{forest}

\begin{document}

\begin{forest} for tree={ folder, grow'=0, align=left }, [ Top level [ \textbf{ABC} ] [ \textbf{123} Also some longer text.\Also some longer text. Also some longer text. Also some longer text. Also some longer text.\Also some longer text. Also some longer text. Also some longer text. Also some longer text.\Also some longer text. Also some longer text.] [ \textbf{ZYX} ] ] \end{forest}

\end{document}

quazgar
  • 1,273

1 Answers1

5

It can be done, although the solution is a bit hacky.

First of all, I added base=top. Behind the hoods, align=center creates a tabular environment and base=top sets the t vertical alignment. This gets us to the base of the first line.

To draw the edge, I set the edge path manually. I took the definition from the folder style (in forest-lib-edges.sty) and adapted the second coordinate to ([yshift=.6ex].base west) --- so base west and shifted up a bit (adjust .6ex to your taste).

\documentclass[a4paper]{article}
\usepackage{geometry}% geometry or similar is needed for correct A4 layout
\usepackage[edges]{forest}

\begin{document}

\begin{forest} for tree={ folder, grow'=0, align=left, }, [ Top level [ \textbf{ABC} ] [ \textbf{123} Also some longer text.\Also some longer text. Also some longer text. Also some longer text. Also some longer text.\Also some longer text. Also some longer text. Also some longer text. Also some longer text.\Also some longer text. Also some longer text., edge path'/.expanded={ ([xshift=\forestregister{folder indent}]!u.parent anchor) |- ([yshift=.6ex].base west) }, base=top, ] [ \textbf{ZYX} ] ] \end{forest}

\end{document}

enter image description here

  • This works perfectly for me, I put it into a custom style in my \forestset as long description/.style={edge path'..., base=top}. Maybe this could be added to the package as a default style? – quazgar Oct 30 '20 at 09:02
  • This might be a bit too specific to be the default. But I'm thinking of a better way to define folder (see e.g. my recent answers to https://tex.stackexchange.com/q/567434/16819) and to deal with (forest's) anchors in general (like the ability to shift them). – Sašo Živanović Oct 30 '20 at 10:07