3

I have the following code sample with the "forest"-environment.

\documentclass{article}

\usepackage{lscape}
\usepackage[edges]{forest}
\usetikzlibrary{arrows.meta}

\begin{document}

\tikzset{
  block/.style={draw, fill=white!20, text width=2cm, text centered, rounded corners, minimum height=1.3cm},
  line/.style={draw, very thick, color=black!80, -Stealth},
}

\begin{landscape}
\begin{forest}
  arrow to/.style n args=4{%
    delay={%
      tikz+={%
        \draw [every edge, line] () -- (!#1) node [above, midway] {#2};
      },
    },
    !u.s sep+=30pt,
  },
  for tree={%
    parent anchor=south,
    child anchor=north,
    calign=center,
    grow=south,
    block,
    base=bottom, 
    edge={line},
    l sep+=10pt,
    where n children=0{tier=word}{},
    font=\footnotesize
  },
  forked edges,
    [Fehler Injektion
        [Echte Hardware
            [Physikalische Injektion
                [Kontaktlose Injektion
                ]
                [Kontakt Injektion
                ]
            ]
        [Software
            [Code Modifikation
            ]
            [Laufzeit
            ]
        ]
        ]
    [Imitierende Hardware
        [Simulation
            [Code Modifikation
            ]
            [Laufzeit
            ]
        ]
        [Emulation
            [Rekonfi-\\guration
            ]
            [Hilfsmech-\\anismen 
            ]
        ]
    ]
    ]
\end{forest}
\end{landscape}

\end{document}

It should look something like this: enter image description here

I have the problem, that my nodes don't align right on the level they should. The "Laufzeit" nodes should be a little bit lower, like the "Software", "Simulation" and "Emulation" nodes. Does anybody have an idea? Thank you in advance!

1 Answer 1

3

You only need to add anchor=center.

\documentclass{article}

\usepackage{lscape}
\usepackage[edges]{forest}
\usetikzlibrary{arrows.meta}

\begin{document}

\tikzset{
  block/.style={draw, fill=white!20, text width=2cm, text centered, rounded corners, minimum height=1.3cm},
  line/.style={draw, very thick, color=black!80, -Stealth},
}

\begin{landscape}
\begin{forest}
  arrow to/.style n args=4{%
    delay={%
      tikz+={%
        \draw [every edge, line] () -- (!#1) node [above, midway] {#2};
      },
    },
    !u.s sep+=30pt,
  },
  for tree={%
    parent anchor=south,
    child anchor=north,
    calign=center,
    anchor=center,
    grow=south,
    block,
    base=bottom, 
    edge={line},
    l sep+=10pt,
    where n children=0{tier=word}{},
    font=\footnotesize
  },
  forked edges,
    [Fehler Injektion
        [Echte Hardware
            [Physikalische Injektion
                [Kontaktlose Injektion
                ]
                [Kontakt Injektion
                ]
            ]
        [Software
            [Code Modifikation
            ]
            [Laufzeit
            ]
        ]
        ]
    [Imitierende Hardware
        [Simulation
            [Code Modifikation
            ]
            [Laufzeit
            ]
        ]
        [Emulation
            [Rekonfi-\\guration
            ]
            [Hilfsmech-\\anismen 
            ]
        ]
    ]
    ]
\end{forest}
\end{landscape}

\end{document}

enter image description here

5
  • 1
    Tex.stackexchange tells me not to write comments like "Thanks", but thank you, @marmot ! You answered another question of mine a few days ago, too. You are my hero!
    – AndiYo
    Sep 23, 2018 at 23:57
  • 2
    P.S. @AndiYo: marmot is the hero of several of us. :)
    – manooooh
    Sep 24, 2018 at 0:13
  • 1
    @manooooh I think you forgot that I lost my crystal ball. So I can no longer pretend to have some skills. :-(
    – user121799
    Sep 24, 2018 at 2:06
  • But you have some native skills.
    – manooooh
    Sep 24, 2018 at 2:35
  • 2
    @manooooh Yes, I am really good at eating and hibernating. ;-)
    – user121799
    Sep 24, 2018 at 2:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .