2

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

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

  • I'm sorry to bother you again. I have encountered a new problem in the forthcoming work of this graph which I can't solve, see this: tex.stackexchange.com/q/254591/44227, it's much appreciated if you can help me or give me some hints. Thanks in advance! – wayne Jul 10 '15 at 3:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.