I can't figure out how to align the following tree properly.
The tree itself is not centered within the page and the branches are not aligned vertically nor horizontally.
I'd like the nodes to be aligned on some sort of invisible grid, and the whole thing to be centered in one single page.
Edited for clarification:
- The pink circle shows that the tree should be centered.
- The green lines show that these boxes are not aligned horizontally.
- The blue lines area: these attempt to show the invisible grid along which the nodes should be aligned vertically. In other words, the space between the blue lines should be the same throughout. Right now, for instance, the 8th Level nodes are not aligned with each other. Moreover, the space between the 7th level node and the 8th Level nodes is not the same as the space between the 8th Level nodes and the 9th Level node. Ideally, all of these spaces should be the same throughout.
I've tried to adjust the space between the various Levels manually (by adding a centimeter here or 4.5 cm there), but it's not working
\documentclass{book}
\usepackage[linguistics,edges]{forest}
\begin{document}
\begin{forest}
for tree={s sep=8mm,
inner sep=4,
l=0,
forked edge,
edge={->,>=latex}}
[Priest,rounded rectangle,draw
[Matador\\ \textit{\small 1st Level},rounded rectangle,draw
[\textbf{Green Branch},rectangle,draw
[Junior Junior\\ \textit{\small 2nd Level},rounded rectangle,draw,
[Chief Eater Booster\\ \textit{\small 8th Level},rounded rectangle,draw,l=130pt
[High Chief\\ \textit{\small 10th Level},rounded rectangle,draw,l=2cm
[Grand Cookie Horsey\\ \textit{\small 12th Level},rounded rectangle,draw,l=2cm
[Obvious Receptacle\\ \textit{\small 15th Level},rounded rectangle,draw,]]]]]]
[\textbf{Ecclesiastical Branch},rectangle,draw,calign with current
[Junior Driver\\ \textit{\small 2nd Level},rounded rectangle,draw,
[Library Leader\\ \textit{\small 8th Level},rounded rectangle,draw,l=4.5cm
[Hotel Commandant\\ \textit{\small 10th Level},rounded rectangle,draw,l=2cm
[Senior Ant-eater\\ \textit{\small 12th Level},rounded rectangle,draw,l=2cm
[Administrative Daddy\\ \textit{\small 15th Level},rounded rectangle,draw,
[Mommy\\ \textit{\small 16th-17th Level},rounded rectangle,draw,l=1cm
[Grand Lord\\ \textit{\small 19th-20th Level},rounded rectangle,draw,l=1cm
[Grand Grandiose\\ \textit{\small 20th Level \& up},rounded rectangle,draw]]]]]]]]]
[\textbf{Military Branch},rectangle,draw
[Walker\\ \textit{\small 2nd Level},rounded rectangle,draw,
[Senior Walker\\ \textit{\small 5th Level},rounded rectangle,draw,
[Ranking Interviewer\\ \textit{\small 7th Level},rounded rectangle,draw,
[Astronaut\\ \textit{\small 9th Level},rounded rectangle,draw,l=2.3cm
[Doctor\\ \textit{\small 11th Level},rounded rectangle,draw,l=2cm
[Great Doctor\\ \textit{\small 16th Level},rounded rectangle,draw,l=3.5cm]]]]]]]
]
]
\end{forest}
\end{document}
Best Answer
If you say e.g.
tier=l2
for several nodes, then Forest will align those nodes (if possible). To centre the tree on the page, you have to do something outside theforest
environment, such as using thecenter
environment. However, space is at a premium, so I use\centering
here to avoid the extra vertical space. I've also addedgeometry
which defaults to slightly more sensible margins and reduced the separation andinner sep
to accommodate everything. I've usedfit=band
to make sure things don't overlap column-wise and some empty nodes to specify missing tiers. If you don't need to represent missing tiers spatially, you could remove some of these and put theinner sep
back to4
. You could also do this if your text height is larger thangeometry
's default (or if you're using A4, say).I've added the
showframe
option to show the text block and margins etc. Obviously, you should remove this in your real document!