7
  • I use forest for the first time and have trouble understanding the (very good) manual.
  • I want to make the tree more compact (see annotation).
  • Which parameter controls that?

\documentclass{article}
\usepackage[edges]{forest}

\begin{document}

\begin{forest} forked edges,
for tree = { align = center, % needed for "\" in nodes. draw, font = \tiny,
where level = 0{ }{ folder, grow' = 0, },
}, [0 [1] [\ldots] [2 [2.1] [2.2] [\ldots] ] [3 [3.1] [3.2]
] [4 [4.1 [4.1.1] [4.1.2] [4.1.3] [4.1.4] [4.1.5]
]
[5.1 [5.1.1] [5.1.2] [5.1.3] [5.1.4] [5.1.5]
]
] ] \end{forest}

\end{document}

enter image description here


Related

1 Answers1

8

The topmost gap can be shortened using l=something on the children of the root (I have set it to 0.6 of the original l), but note that as we are shortening the distance, we also need to set l sep=0 on the root node.

The other gaps are artefacts of using folder multiple times on each node. The thing is, in the original code, folder resides within two loops, for tree and where level. That's a bad idea even in general, as it uses more time, but in this tree, the effect is visible as well. I usually suggest if level instead of where level in these cases, but here, for tree followed by for descendants seems even more elegant.

\documentclass{article}
\usepackage[edges]{forest}

\begin{document}

\begin{forest} forked edges, l sep = 0, for children = {l*= 0.6}, for tree = { align = center, % needed for "\" in nodes. draw, font = \tiny,
}, for descendants={ grow' = 0, folder, }, [0 [1] [\ldots] [2 [2.1] [2.2] [\ldots] ] [3 [3.1] [3.2]
] [4 [4.1 [4.1.1] [4.1.2] [4.1.3] [4.1.4] [4.1.5]
]
[5.1 [5.1.1] [5.1.2] [5.1.3] [5.1.4] [5.1.5]
]
] ] \end{forest}

\end{document}

the result of compilation