GeneralForest horizontal node alignement

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
cyanidebaby
Posts: 11
Joined: Tue Feb 07, 2017 1:56 pm

Forest horizontal node alignement

Post by cyanidebaby »

Hello,

There are three, sharp-cornered, rectangular boxes at the top of the "forest table" which code I've pasted under. Let's call them the "Branch boxes".

The blank spaces between these "branch boxes" is not even, horizontally.
How do I make these spaces even?

Thank you.

Code: Select all

\documentclass{book}
\usepackage{geometry}
\usepackage[linguistics,edges]{forest}

\begin{document}
\begingroup
\centering
\begin{forest}
  for tree={
    l'=0pt,
    edge={->,>=latex},
    draw,
    fit=band,
    inner sep=2,
  },
  nice empty nodes,
  delay={
    where content={}{edge=-}{},
  },
  where level=2{}{rounded rectangle},
  forked edges,
  [Priest
    [Matador\\\textit{\small 1st Level}, tier=l1
      [\textbf{Green Branch},rounded corners=0pt
        [Junior Junior\\\textit{\small 2nd Level}, tier=l2,
          [Chief Eater Booster\\\textit{\small 8th Level}, tier=l8,
            [High Chief\\\textit{\small 10th Level}, tier=l10,
              [Grand Cookie Horsey\\\textit{\small 12th Level}, tier=l12,
                [Obvious Receptacle\\\textit{\small 15th Level}, tier=l15,]]]]]]
      [\textbf{Ecclesiastical Branch},rectangle,calign with current
        [Junior Driver\\\textit{\small 2nd Level}, tier=l2,
          [Library Leader\\\textit{\small 8th Level}, tier=l8,
            [Hotel Commandant\\\textit{\small 10th Level}, tier=l10,
              [Senior Ant-eater\\\textit{\small 12th Level}, tier=l12,
                [Administrative Daddy\\\textit{\small 15th Level}, tier=l15,
                  [Mommy\\\textit{\small 16th-17th Level}, tier=l17,
                    [, tier=l18 [Grand Lord\\\textit{\small 19th-20th Level}, tier=l19
                      [Grand Grandiose\\\textit{\small 20th Level \& up}, tier=l20]]]]]]]]]]
      [\textbf{Military Branch},rectangle
        [Walker\\\textit{\small 2nd Level}, tier=l2,
          [, tier=l3 [, tier=l4 [Senior Walker\\\textit{\small 5th Level}, tier=l5,
            [, tier=l6 [Ranking Interviewer\\\textit{\small 7th Level}, tier=l7,
              [, tier=l8
                [Astronaut\\\textit{\small 9th Level}, tier=l9,
                  [,tier=l10 [Doctor\\\textit{\small 11th Level}, tier=l11,
                    [,tier=l12 [,tier=l13 [,tier=l14 [,tier=l15 [Great Doctor\\\textit{\small 16th Level}, tier=l16,]]]]]]]]]]]]]]]]
    ]
  ]
\end{forest}
\par
\endgroup
\end{document}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
Stefan Kottwitz
Site Admin
Posts: 10324
Joined: Mon Mar 10, 2008 9:44 pm

Forest horizontal node alignement

Post by Stefan Kottwitz »

Hello,

that's for symmetry: if you would make the spaces even, the whole branches would have a different distance to the middle. I thing an overall asymmetry is more bad than a single internal distance.

But there's another solution other than to change the spacing itself: make the width of the boxes equal, such as

Code: Select all

[\textbf{Green Branch},rounded corners=0pt,minimum width=4cm
...
[\textbf{Ecclesiastical Branch},rectangle,minimum width=4cm,
...
[\textbf{Military Branch},rectangle,minimum width=4cm
...
Just choose the minimum width so that the widest text fits. It can be automatically measured though, such as by using \settowidth. For repeating things, such as rectangle style with the same width, I would introduce a style.

Stefan
LaTeX.org admin
cyanidebaby
Posts: 11
Joined: Tue Feb 07, 2017 1:56 pm

Forest horizontal node alignement

Post by cyanidebaby »

Thanks very much, Stefan.
That works.

I guess I'm just going to have to figure out which look I prefer!

Thanks again.
Post Reply