将绿色框移至右侧灰色框的顶部

将绿色框移至右侧灰色框的顶部

以下是我从森林风格修改的图表,但是当我尝试将绿色框移至右侧灰色框的顶部,我知道主要问题是树形风格,但我无法弄清楚,我寻求您的帮助,提前谢谢。

我的代码:

\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},
}
%
\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,
    align=left, no edge
}  
[Nonlinear\\Stochastic\\Systems, root 
  [{Applications to NCSs, CNs\\ GRNs}, no edge, inner ysep=0pt, tikz={\node [draw,  blue, fit=() (!n) (!nn) (!nnn), inner sep=1pt] {};},name=bottom]
       [\textbf{Chapter 8}  CNs, tnode]
        [\textbf{Chapter 7} NCSs, tnode]
        [\textbf{Chapter 5} GRNs, tnode] 
  [{Analysis and Synthesis for \\ Systems with \\ Incomplete Information}, inner ysep=0pt, no edge, tikz={\node [draw,  blue, fit=() (!n) (!nn) (!nnn)(!nnnn), inner sep=1pt] {};},name=middle]
    [\textbf{Chapter 11} RVOs, tnode] 
     [{\textbf{Chapter 9} RONs},tnode]
    [{\textbf{Chapter 10} MMs},tnode]
    [\textbf{Chapter 6}  {MMs, SNs}, tnode]
    [{Analysis and Synthesis for\\ Systems with   General \\Engineering Phenomenon}, inner ysep=0pt, no edge, tikz={\node [draw, blue, fit=()(!n) (!nn) (!nnn)(!nnnn), inner sep=1pt] {};}]
     [\textbf{Chapter 12} {TDs, GNs},tnode]
              [\textbf{Chapter 4} {TDs, MJ, SNs}, tnode] 
         [\textbf{Chapter 3} {TDs, MJ, NDs}, tnode]
         [\textbf{Chapter 2} {TDs, NDs}, tnode ,name=top] 
]
\node [draw,  black!40, inner sep=.4em, fit={(top)(middle)(bottom)} ] {};
\end{forest}
\end{document}

在此处输入图片描述

答案1

这种树形样式的典型方法是将根与您想要的子项对齐。在本例中,它将是calign=last。如果您想将其与灰色框对齐,则必须手动将其稍微移动。这可能看起来像这样:

% arara: pdflatex

\documentclass[margin=10pt]{standalone}
\usepackage{forest}
\usetikzlibrary{shadows}
\tikzset{%
    basic/.style = {draw, thin, drop shadow, font=\sffamily},
    root/.style = {basic, rounded corners=2pt, fill=green!30, text width=2cm}, % I have deleted all the alignments here, as they get overwritten in your `for tree={}`
    onode/.style = {basic, rounded corners=2pt, fill=green!60, text width=3cm,},
    tnode/.style = {basic, fill=pink!60},
}

\begin{document}
    \begin{forest} for tree={%
            ,anchor=base west
            ,grow=0
            ,l sep+=1em
            ,align=left
            ,no edge
        }  
        [Nonlinear\\Stochastic\\Systems, root, calign=last, yshift=.15cm
        [{Applications to NCSs, CNs\\ GRNs}, inner ysep=0pt, tikz={\node [draw,  blue, fit=() (!n) (!nn) (!nnn), inner sep=1pt] {};},name=bottom]
        [\textbf{Chapter 8}  CNs, tnode]
        [\textbf{Chapter 7} NCSs, tnode]
        [\textbf{Chapter 5} GRNs, tnode] 
        [{Analysis and Synthesis for \\ Systems with \\ Incomplete Information}, inner ysep=0pt, tikz={\node [draw,  blue, fit=() (!n) (!nn) (!nnn)(!nnnn), inner sep=1pt] {};},name=middle]
        [\textbf{Chapter 11} RVOs, tnode] 
        [{\textbf{Chapter 9} RONs},tnode]
        [{\textbf{Chapter 10} MMs},tnode]
        [\textbf{Chapter 6}  {MMs, SNs}, tnode]
        [{Analysis and Synthesis for\\ Systems with   General \\Engineering Phenomenon}, inner ysep=0pt, tikz={\node [draw, blue, fit=()(!n) (!nn) (!nnn)(!nnnn), inner sep=1pt] {};}]
        [\textbf{Chapter 12} {TDs, GNs},tnode]
        [\textbf{Chapter 4} {TDs, MJ, SNs}, tnode] 
        [\textbf{Chapter 3} {TDs, MJ, NDs}, tnode]
        [\textbf{Chapter 2} {TDs, NDs}, tnode ,name=top] 
        ]
        \node [draw,  black!40, inner sep=.4em, fit={(top)(middle)(bottom)} ] {};
    \end{forest}
\end{document}

在此处输入图片描述


正如评论中所述,您希望将所有框放在一行中。因此,您必须将它们放在同一级别。说实话,我不明白在这里使用某些树有什么意义。但你在这里:

\begin{document}
    \begin{forest} for tree={%
            ,anchor=base west
            ,grow=0
            ,align=left
            ,no edge
        }  
        [       
        [{Applications to NCSs, CNs\\ GRNs}, inner ysep=0pt, tikz={\node [draw,  blue, fit=() (!n) (!nn) (!nnn), inner sep=1pt] {};},name=bottom]
        [\textbf{Chapter 8}  CNs, tnode]
        [\textbf{Chapter 7} NCSs, tnode]
        [\textbf{Chapter 5} GRNs, tnode] 
        [{Analysis and Synthesis for \\ Systems with \\ Incomplete Information}, inner ysep=0pt, tikz={\node [draw,  blue, fit=() (!n) (!nn) (!nnn)(!nnnn), inner sep=1pt] {};},name=middle]
        [\textbf{Chapter 11} RVOs, tnode] 
        [{\textbf{Chapter 9} RONs},tnode]
        [{\textbf{Chapter 10} MMs},tnode]
        [\textbf{Chapter 6}  {MMs, SNs}, tnode]
        [{Analysis and Synthesis for\\ Systems with   General \\Engineering Phenomenon}, inner ysep=0pt, tikz={\node [draw, blue, fit=()(!n) (!nn) (!nnn)(!nnnn), inner sep=1pt] {};}]
        [\textbf{Chapter 12} {TDs, GNs},tnode]
        [\textbf{Chapter 4} {TDs, MJ, SNs}, tnode] 
        [\textbf{Chapter 3} {TDs, MJ, NDs}, tnode]
        [\textbf{Chapter 2} {TDs, NDs}, tnode ,name=top] 
        [Nonlinear\\Stochastic\\Systems, root, yshift=2cm, xshift=1cm] % shifting is optional here
        ]
        \node [draw,  black!40, inner sep=.4em, fit={(top)(middle)(bottom)} ] {};
    \end{forest}
\end{document}

在此处输入图片描述

答案2

这是使用默认生长方向绘制树的方法。请注意,这需要forest版本 1.09(或可能更高版本)。

\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 n args=2{
    tikz+={\node (#2) [fitbox, fit=#1] {};},
    inner sep=0pt,
  }
}
\begin{document}
\title{Structure of Book}
\begin{forest}
  for tree={
    align=left,
    font=\sffamily,
    no edge,
    child anchor=north west,
    inner sep=1pt,
    if level=0{
      parent anchor=south,
      l sep+=5mm,
    }{
      calign=child edge,
      parent anchor=south west,
    },
  }
  [Nonlinear\\Stochastic\\Systems, root
    [\textbf{Chapter 2} {TDs, NDs}, tnode
      [\textbf{Chapter 3} {TDs, MJ, NDs}, tnode, name=widest
        [\textbf{Chapter 4} {TDs, MJ, SNs}, tnode
          [\textbf{Chapter 12} {TDs, GNs},tnode
          [{Analysis and Synthesis for\\ Systems with   General \\Engineering Phenomenon}, fitting={() (!u) (!uu) (!uuu)(!uuuu)}{f1}
    [\textbf{Chapter 6}  {MMs, SNs}, tnode
      [{\textbf{Chapter 9} RONs},tnode
        [{\textbf{Chapter 10} MMs},tnode
          [\textbf{Chapter 11} RVOs, tnode
          [{Analysis and Synthesis\\for Systems with\\Incomplete Information},  fitting={(!u) () ( -| widest.east) (!uu) (!uuuu) (!uuu)}{f2}
    [\textbf{Chapter 5} GRNs, tnode
      [\textbf{Chapter 7} NCSs, tnode
       [\textbf{Chapter 8}  CNs, tnode
       [{Applications to\\NCSs, CNs, GRNs}, fitting={(!uuu) () (!u) (!uu) ( -| widest.east)}{f3}, fitting={(f1) (f2) (f3)}{f4}
    ]]]]]]]]]]]]]]
  ]
\end{forest}
\end{document}

向南生长

相关内容