森林:节点对齐

森林:节点对齐

我有以下具有“森林”环境的代码示例。

\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}

它看起来应该是这样的: 在此处输入图片描述

我遇到了一个问题,我的节点没有对齐到应有的水平。“Laufzeit”节点应该稍微低一点,就像“Software”、“Simulation”和“Emulation”节点一样。有人有想法吗?提前谢谢!

答案1

您只需添加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}

在此处输入图片描述

相关内容