如何在森林环境中改变根节点中父锚点的位置?

如何在森林环境中改变根节点中父锚点的位置?

我有这个代码

\PassOptionsToPackage{rgb,svgnames,dvipsnames,x11names}{xcolor}
\documentclass[border=10pt,tikz]{standalone}
\usepackage{forest}
\usepackage{chemformula}

\forestset{% this specifies a style, direction switch, which manages the layout, formatting and tweaking of the various levels and nodes of the tree itself
  direction switch/.style={
    for tree={l sep=-10em,
      draw=DodgerBlue2,
      thick,
      inner ysep=2pt,
      edge={thick},
      if level=1{% the root node is level 0 so this is the layer of horizontally aligned nodes beneath it
        parent anchor=south,
        child anchor=north,
        edge path={
          \noexpand\path [draw, \forestoption{edge}] (!u.parent anchor) -- ++(0,-.5em) -| (.child anchor)\forestoption{edge label};
        },
        for descendants={% apply to everything beneath level 1
          child anchor=west,
          align=left,
          edge path={
            \noexpand\path [draw, \forestoption{edge}] (!u.parent anchor) ++(1em,0) |- (.child anchor)\forestoption{edge label};
          },
          s sep+=1.5pt,
          fit=band,
        },
        for tree={% apply to everything in level 1 or beneath level 1
          parent anchor=south west,
          anchor=mid west,
          grow'=0,
          font=\sffamily,
          if n children=0{}{
            delay={
              prepend={[,phantom, calign with current]}
            }
          },
          before computing xy={
            l=2em
          }
        },
      }{
        if level=0{% this is the root node of the tree, level 0
          parent anchor=south,
          anchor=south,
          before drawing tree={% we repack just the top bit of the tree, right at the end, to account for the increased spacing introduced by moving things around; after repacking, we need to explicitly recompute the x-y coordinates as well, before the tree is drawn
            pack',
            compute xy,
          }
        }{},
      },
    },
  }
}


\begin{document}
\begin{forest}
  % forest preamble: determine layout and format of tree
  direction switch% apply the style defined above
  % specify the content of the tree
  [{Dry Air Oxidation (\ch{U + O2})}
    [Chemical Diffusion
      [Quasi-steady diffusion
        [Comparison with GK model
        ]
      ]
      [Unsteady diffusion
        [Neglecting volumetric changes
            [Numerical  + Analytical\\ + Asymptotics]
        ]
        [Including volumetric changes
            [Numerical solution]
        ]
      ]
    ]
    [Ionic Diffusion
      [Moderate Electric Field
        [Quasi-steady diffusion]
        [Unsteady diffusion]
      ]
      [Strong Electric Field
        [Quasi-steady]
        [Unsteady diffusion]
      ]
    ]
  ]
\end{forest}
\end{document}

生成结果: 这个文件。我希望能够从根节点改变锚点的位置;换句话说,以“干空气氧化”为中心。

答案1

如果您对近似解决方案感到满意,那么只需添加parent anchor=-160

\PassOptionsToPackage{rgb,svgnames,dvipsnames,x11names}{xcolor}
\documentclass[border=10pt,tikz]{standalone}
\usepackage{forest}
\usepackage{chemformula}

\forestset{% this specifies a style, direction switch, which manages the layout, formatting and tweaking of the various levels and nodes of the tree itself
  direction switch/.style={
    for tree={l sep=-10em,
      draw=DodgerBlue2,
      thick,
      inner ysep=2pt,
      edge={thick},
      if level=1{% the root node is level 0 so this is the layer of horizontally aligned nodes beneath it
        parent anchor=south,
        child anchor=north,
        edge path={
          \noexpand\path [draw, \forestoption{edge}] (!u.parent anchor) -- ++(0,-.5em) -| (.child anchor)\forestoption{edge label};
        },
        for descendants={% apply to everything beneath level 1
          child anchor=west,
          align=left,
          edge path={
            \noexpand\path [draw, \forestoption{edge}] (!u.parent anchor) ++(1em,0) |- (.child anchor)\forestoption{edge label};
          },
          s sep+=1.5pt,
          fit=band,
        },
        for tree={% apply to everything in level 1 or beneath level 1
          parent anchor=south west,
          anchor=mid west,
          grow'=0,
          font=\sffamily,
          if n children=0{}{
            delay={
              prepend={[,phantom, calign with current]}
            }
          },
          before computing xy={
            l=2em
          }
        },
      }{
        if level=0{% this is the root node of the tree, level 0
          parent anchor=south,
          anchor=south,
          before drawing tree={% we repack just the top bit of the tree, right at the end, to account for the increased spacing introduced by moving things around; after repacking, we need to explicitly recompute the x-y coordinates as well, before the tree is drawn
            pack',
            compute xy,
          }
        }{},
      },
    },
  }
}


\begin{document}
\begin{forest}
  % forest preamble: determine layout and format of tree
  direction switch% apply the style defined above
  % specify the content of the tree
  [{Dry Air Oxidation (\ch{U + O2})},parent anchor=-160
    [Chemical Diffusion
      [Quasi-steady diffusion
        [Comparison with GK model
        ]
      ]
      [Unsteady diffusion
        [Neglecting volumetric changes
            [Numerical  + Analytical\\ + Asymptotics]
        ]
        [Including volumetric changes
            [Numerical solution]
        ]
      ]
    ]
    [Ionic Diffusion
      [Moderate Electric Field
        [Quasi-steady diffusion]
        [Unsteady diffusion]
      ]
      [Strong Electric Field
        [Quasi-steady]
        [Unsteady diffusion]
      ]
    ]
  ]
\end{forest}
\end{document}

在此处输入图片描述

您还可以计算节点锚点。这是通过在案例中使用([xshift={2pt+0.5*width("Dry Air Oxidation")}]!u.south west)而不是 来实现的。(!u.parent anchor)level=1

\PassOptionsToPackage{rgb,svgnames,dvipsnames,x11names}{xcolor}
\documentclass[border=10pt,tikz]{standalone}
\usepackage{forest}
\usepackage{chemformula}

\forestset{% this specifies a style, direction switch, which manages the layout, formatting and tweaking of the various levels and nodes of the tree itself
  direction switch/.style={
    for tree={l sep=-10em,
      draw=DodgerBlue2,
      thick,
      inner ysep=2pt,
      edge={thick},
      if level=1{% the root node is level 0 so this is the layer of horizontally aligned nodes beneath it
        parent anchor=south,
        child anchor=north,
        edge path={
          \noexpand\path [draw, \forestoption{edge}] 
          ([xshift={2pt+0.5*width("Dry Air Oxidation")}]!u.south west) -- ++(0,-.5em) -| (.child anchor)\forestoption{edge label};
        },
        for descendants={% apply to everything beneath level 1
          child anchor=west,
          align=left,
          edge path={
            \noexpand\path [draw, \forestoption{edge}] (!u.parent anchor) ++(1em,0) |- (.child anchor)\forestoption{edge label};
          },
          s sep+=1.5pt,
          fit=band,
        },
        for tree={% apply to everything in level 1 or beneath level 1
          parent anchor=south west,
          anchor=mid west,
          grow'=0,
          font=\sffamily,
          if n children=0{}{
            delay={
              prepend={[,phantom, calign with current]}
            }
          },
          before computing xy={
            l=2em
          }
        },
      }{
        if level=0{% this is the root node of the tree, level 0
          parent anchor=south,
          anchor=south,
          before drawing tree={% we repack just the top bit of the tree, right at the end, to account for the increased spacing introduced by moving things around; after repacking, we need to explicitly recompute the x-y coordinates as well, before the tree is drawn
            pack',
            compute xy,
          }
        }{},
      },
    },
  }
}


\begin{document}
\begin{forest}
  % forest preamble: determine layout and format of tree
  direction switch% apply the style defined above
  % specify the content of the tree
  [{Dry Air Oxidation (\ch{U + O2})}
    [Chemical Diffusion
      [Quasi-steady diffusion
        [Comparison with GK model
        ]
      ]
      [Unsteady diffusion
        [Neglecting volumetric changes
            [Numerical  + Analytical\\ + Asymptotics]
        ]
        [Including volumetric changes
            [Numerical solution]
        ]
      ]
    ]
    [Ionic Diffusion
      [Moderate Electric Field
        [Quasi-steady diffusion]
        [Unsteady diffusion]
      ]
      [Strong Electric Field
        [Quasi-steady]
        [Unsteady diffusion]
      ]
    ]
  ]
\end{forest}
\end{document}

\documentclass{beamer}
\usepackage[edges]{forest}
\begin{document}
\begin{frame}[t]
\frametitle{A tree}
\centering
\begin{forest}
forked edges,
for tree={rounded corners,draw,fill=gray!20,font=\sffamily,
    align=left,text width=7em,s sep+=0.5em}
[\textbf{Approach}
 [{\textbf{location-based}\\[1.2em] blub}]
 [{\textbf{inertia-based}\\[1.2em] blah}]
 [{\textbf{hybrid}\\[1.2em] pft}]
]
\end{forest}
\end{frame}
\end{document}

在此处输入图片描述

相关内容