2

The expected behavior of the following code would be that nodes descending from a myFolder node are positioned below the parent node with some indentation.

As you can see from the image, however, it would seem that the direct children of the myFolder node are positioned so that their left side is aligned with the center of the parent node.

Is there any way to fix this?

I would also like to understand how to align nodes on the same level with different heights at the top and not at the center.

\usepackage[edges]{forest}
\usetikzlibrary{calc}
\usetikzlibrary{positioning}

\forestset{ declare boolean={folderDescendants}{false}, myFolder/.style={ l sep = 0, for tree={ grow'=0, folder, align=center, s sep'=1mm, minimum height=5mm, }, folder indent'=5mm, for descendants={ folderDescendants, inner xsep=2mm, inner ysep=0mm, edge path'/.expanded={ ([xshift=\forestregister{folder indent}]!u.parent anchor) |- ([yshift=.6ex].base west) }, }, }, myFork/.style={ for tree={ fit=band, rounded corners, ultra thick, font=\sffamily\bfseries\Large, inner xsep=5mm, inner ysep=5mm, edge+={ultra thick, rounded corners}, align=center, l sep'=20mm, s sep'=7mm, fork sep'=8mm, align = center, }, forked edges, before typesetting nodes={ where folderDescendants={}{ draw, minimum height=15mm, minimum width=20mm, anchor=center, }, }, }, }

\begin{document} \begin{forest} myFork, [Root,calign=child, calign child=2 [Lorem ipsum, myFolder [Lorem ipsum dolor sit amet [Lorem ipsum dolor sit amet] [Lorem ipsum dolor sit amet] [Lorem ipsum dolor sit amet] ] [Lorem ipsum dolor sit amet] [Lorem ipsum] ] [Lorem ipsum dolor sit amet [Lorem ipsum dolor sit amet] [Lorem ipsum\dolor sit amet] [Lorem ipsum dolor sit amet,myFolder [Lorem 4 [Lorem ipsum dolor sit amet] [Lorem ipsum dolor sit amet] [Lorem ipsum dolor sit amet] ] [Lorem 5.1\Lorem 5.2\Lorem 5.3] [Lorem 6] ] ] [Lorem ipsum\dolor sit amet] [Lorem ipsum] [Lorem ipsum] ] \end{forest} \end{document}

The current situation enter image description here

The desired result (in green and fuchsia I have highlighted the spaces that I would like to modify)

enter image description here

The desired result with possible alignment to the top of the nodes

enter image description here

Datboi
  • 85
  • If you change anchor=center to anchor=north the nodes with a border get top-aligned (might need you to adjust the distance to its first child, though). – Qrrbrbirlbel Jul 08 '23 at 21:38
  • Please post compilable code with \documentclass{} etc. – cfr Jul 09 '23 at 00:17
  • What's the fuchsia in the first diagram indicating? – cfr Jul 09 '23 at 00:21
  • Also, if you adapted this code from somewhere, please post a link. – cfr Jul 09 '23 at 00:24
  • 1
    Sorry for the inadequate structure of the question.

    The fuchsia lines in the first image indicated the need to maintain the same space between the various subtrees, while in the second image they indicated that the nodes were horizontally aligned at the top.

    Regarding the links I had read several discussions online and had not kept track of the pages so I would not have been able to indicate the sources.

    Anyway thanks for these indications, next time I will try to pay more attention to these things.

    – Datboi Jul 11 '23 at 10:11

1 Answers1

2

I'm not entirely sure what you want. However, this at least aligns the tops of the drawn nodes and removes the additional indentation of the folder nodes.

Significant bits of your code appeared to be at odds with your desires. Removing those parts fixed some of the issues immediately. Don't just copy forest styles and then try to tweak them. If they don't do what you want, at least look to see if the default settings from the manual do. The inset of the directory-style nodes is in that category: by default, they aren't aligned with the centre of the parent in the first place.

The folder style is tricky and it is difficult to get it to behave as people want when the tree changes direction. I don't think it was really intended to be used this way ;). It would probably be better to use something else, but I don't have any improved styles to offer :(, so it is a question of hacking for particular cases.

\documentclass[border=9pt]{standalone}

\usepackage[edges]{forest} \forestset{ folders down/.style={ for tree={ grow'=0, folder, minimum height=5mm, }, for current and siblings={anchor=north west, child anchor=north}, for current and ancestors={
minimum height=15mm, minimum width=20mm, }, for ancestors={l sep'+=5pt}, for descendants={ draw=none, inner xsep=2mm, inner ysep=0mm, }, }, myFork/.style={ for tree={ fit=band, rounded corners, draw, ultra thick, font=\sffamily\bfseries\Large, inner xsep=5mm, inner ysep=5mm, outer ysep=0pt, edge+={ultra thick},% rounded corners}, replace if you like align=center, }, forked edges, }, }

\begin{document} \begin{forest} myFork, [Root,calign=child, calign child=2 [Lorem ipsum, folders down [Lorem ipsum dolor sit amet [Lorem ipsum dolor sit amet] [Lorem ipsum dolor sit amet] [Lorem ipsum dolor sit amet] ] [Lorem ipsum dolor sit amet] [Lorem ipsum] ] [Lorem ipsum dolor sit amet [Lorem ipsum dolor sit amet] [Lorem ipsum\dolor sit amet, calign with current edge] [Lorem ipsum dolor sit amet, folders down [Lorem 4 [Lorem ipsum dolor sit amet] [Lorem ipsum dolor sit amet] [Lorem ipsum dolor sit amet] ] [Lorem 5.1\Lorem 5.2\Lorem 5.3] [Lorem 6] ] ] [Lorem ipsum\dolor sit amet] [Lorem ipsum] [Lorem ipsum] ] \end{forest} \end{document}

I changed style names because I hardly ever use caps and I kept writing myfolder. Obviously, use whatever names you like. (I left myFork because I didn't have to retype it. So now the code style is inconsistent, to boot.)

tweaked tree

cfr
  • 198,882
  • Thanks a lot for the suggestions, the main problem was definitely related to the anchors. I had tried starting with the manual's default settings but was getting stuck, so I fell back on a mix of solutions found online...

    Anyway thanks again for the help.

    – Datboi Jul 11 '23 at 10:11
  • @Datboi No problem. Like I said, folder is tricky and things get weird very quickly if your tree changes the direction of growth. That seems to be a popular thing to do, but I'm not aware of a general solution. – cfr Jul 11 '23 at 15:18