我想绘制一个包含所有grandchild
s(粉色框)的最小框,并将深绿色框的文本移动到新框的底部。我该怎么做?
代碼:
\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={anchor=base west,
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
[{Applications to Complex Systems, NCSs, GRNs}, onode
[Chapter 8\\ Complex Networks, tnode]
[Chapter 7\\ Networked Control Systems, tnode]
[Chapter 5\\Gene Regulatory Networks, tnode] ]
]
\end{forest}
\end{document}
答案1
更新
这是使用两个框的新版本。我更改了节点之间的空间,以便可以有多个虚线框。
输出
代码
\documentclass[margin=10pt]{standalone}
\usepackage{forest}
\usetikzlibrary{arrows.meta,shapes,positioning,shadows,fit,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={anchor=base west,
grow=east,
growth parent anchor=east,
parent anchor=east,
child anchor=west,l sep+=1em,s sep=5mm,
edge path={\noexpand\path[\forestoption{edge},->, >={latex}]
(!u.parent anchor) -- +(1em,0pt) |- (.child anchor)
\forestoption{edge label};}
}
[Nonlinear Stochastic Systems, root
[Chapter 8\\ Complex Networks, tnode, name=eight]
[Chapter 7\\ Networked Control Systems, tnode, name=seven]
[Chapter 5\\Gene Regulatory Networks, tnode, name=five]
[Chapter 11\\randomly varying nonlinearities, tnode, name=eleven]
[Chapter 6 \, 10\\missing measurement, tnode]
[Chapter 9\\randomly occurring nonlinearities, tnode, name=nine] ] ]
%
\node [draw, dashed, black!40, inner sep=.4em, fit={(eight) (five) (seven)}, label={[align=left]0:Applications to\\Complex Systems,\\NCSs, GRNs}] {};
\node [draw, dashed, black!40, inner sep=.4em, fit={(eleven) (nine)}, label={[align=left]0:Analysis of\\something complex\\more text}] {};
\end{forest}
\end{document}
答案2
这回答了评论中的问题Alenanno 的回答。
如果你想要这样的东西:
\node
如果我们使用相对节点名称并在树本身内指定附加命令,则无需明确命名节点。这可以使用tikz
键或afterthought
键来完成。在下文中,我使用前者。我还修剪了不必要的样式onode
(顺便说一下,它最初代表“橙色节点”)。我还整理了一下并改进了间距,在我之前发布的版本中,间距有点被挤压了。
fitbox
指定用于绘制虚线框的样式。我已将所有节点都设为圆角,因为混合使用看起来很奇怪,但您显然可以调整这一点。
fitting
是一种采用一个参数的样式。这指定要包含在虚线框中的节点。您可以使用明确命名的节点(例如(nine)
命名节点)name=nine
或使用相对节点名称(如我这里所用)。(!n)
是下一个兄弟节点、(!nn)
是下一个兄弟节点的兄弟节点等等。
这使得代码更加清晰,更加易读。
\documentclass[margin=10pt]{standalone}
\usepackage{forest}
\usetikzlibrary{arrows.meta,shadows,fit}
\tikzset{
basic/.style = {draw, text width=2cm, drop shadow},
basic1/.style = {draw, drop shadow, rectangle},
root/.style = {basic, rounded corners=2pt, thin, align=center, fill=green!30},
tnode/.style = {basic1, thin, align=left, fill=pink!60, rounded corners=2pt},
fitbox/.style = {draw, gray, dashed, inner ysep=5pt, inner xsep=7.5pt, rounded corners=2pt},
}
\forestset{
fitting/.style={
tikz={\node [fitbox, fit=#1] {};},
no edge,
inner ysep=0pt,
}
}
\begin{document}
\title{Structure of Book}
\begin{forest}
for tree={
anchor=base west,
grow=east,
parent anchor=east,
parent anchor=east,
child anchor=west,
l sep+=1em,
align=left,
font=\sffamily,
edge={->, >={latex}},
edge path={
\noexpand\path[\forestoption{edge}] (!u.parent anchor) -- +(1em,0pt) |- (.child anchor)\forestoption{edge label};
},
}
[Nonlinear\\Stochastic\\Systems, root
[{Applications to\\Complex Systems,\\NCSs, GRNs}, fitting={(!nnn) (!n) (!nn)}]
[Chapter 8\\ Complex Networks, tnode]
[Chapter 7\\ Networked Control Systems, tnode]
[Chapter 5\\Gene Regulatory Networks, tnode]
[{Analysis and Synthesis\\for Systems with\\Incomplete Information}, fitting={(!n) (!nn) (!nnn)}]
[Chapter 11\\randomly varying nonlinearities, tnode]
[{Chapter 6, 10\\something},tnode]
[{Chapter 9\\randomly occurring somethings},tnode]
]
\end{forest}
\end{document}