如何在森林中对齐文本框?

如何在森林中对齐文本框?

我采用了Alenanno的代码绘制下面的图形,但是遇到一个问题,就是文本框(粉色框)如何左对齐?

在此处输入图片描述

代码如下:

\documentclass{standalone}
\usepackage{forest}
\usetikzlibrary{arrows.meta,shapes,positioning,shadows,trees}

\tikzset{
basic/.style  = {draw, text width=2cm, drop shadow, font=\sffamily, rectangle},
basic1/.style  = {draw,  drop shadow, font=\sffamily, rectangle},
root/.style   = {basic, rounded corners=2pt, thin, align=center,                    fill=green!30},
onode/.style = {basic, thin, rounded corners=2pt, align=center, fill=green!60,text width=3cm,},
tnode/.style = {basic1, thin, align=left, fill=pink!60},
edge from parent/.style={draw=black, edge from parent fork right}
}

\begin{document}
 \title{Structure of Book}
\begin{forest} for tree={
grow=east,
growth parent anchor=east,
parent anchor=east,
child anchor=west,
edge path={\noexpand\path[\forestoption{edge},->, >={latex}] 
     (!u.parent anchor) -- +(5pt,0pt) |- (.child anchor)
     \forestoption{edge label};}
}
[Nonlinear Stochastic Systems, root
[Robust Control and Filtering, onode
    [Chapter 6\\ Robust Filtering, tnode]
    [Chapter 4\\ ${H}_\infty$ Filtering, tnode] 
    [Chapter 3\\ Robust ${H}_\infty$ Control, tnode]
    [Chapter 2\\Robust Stabilization, tnode] ] ]
 \end{forest}
 \end{document}

答案1

您添加了额外的样式,,basic1而这和之间的区别basic在于缺少text width=...

这就是导致对齐奇怪的原因。如果您从 切换tnode/.style = {basic1, ...tnode/.style = {basic, ...,它们将正确对齐。

但是,如果您不想设置文本宽度,请添加anchor=base westfor tree={}选项中。但是您必须知道,这将导致没有文本宽度的节点具有可变宽度。

在此处输入图片描述

相关内容