我采用了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 west
到for tree={}
选项中。但是您必须知道,这将导致没有文本宽度的节点具有可变宽度。