[Tex/LaTex] How to align text boxes in forest

forest

I adopted Alenanno's code to draw the following graph, but I encounter a problem, that is, how to align the text boxes (pink boxes) in left?

enter image description here

and codes are as follows:

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

Best Answer

You added an extra style, basic1, and the difference between this and basic is the lack of text width=....

That's what is causing the weird alignment. If you switch from tnode/.style = {basic1, ... to tnode/.style = {basic, ..., they will align properly.

However, if you don't want to set a text width, add anchor=base west to the for tree={} options. However you must know that this will cause the nodes without text width to have variable widths.

enter image description here

Related Question