帮助使用森林的边缘路径

帮助使用森林的边缘路径

我正在尝试实现下图中用红色标记的路径。如您所见,这些路径对于第二级的孩子来说几乎不可见。

在此处输入图片描述

    \documentclass{article}
    \usepackage[edges]{forest}
    \usetikzlibrary{shadows}
    \usepackage{array}
    \newcolumntype{C}[1]{>{\centering}p{#1}}
    
    \begin{document}
    \scalebox{0.6}{
    \forestset{%
      rect/.append style={rectangle, rounded corners=2pt},
      dir tree switch/.style args={at #1}{%
        for tree={
          fit=rectangle,
        },
        where level=#1{
          for tree={
            folder,
            grow'=0,
          },
          delay={child anchor=north},
        }{},
        before typesetting nodes={
          for tree={
            content/.wrap value={\strut ##1},
          },
          if={isodd(n_children("!r"))}{
            for nodewalk/.wrap pgfmath arg={{fake=r,n=##1}{calign with current edge}}{int((n_children("!r")+1)/2)},
          }{},
        },
      },
    }
    
    
    \begin{forest}
      dir tree switch=at 1,
      for tree=
      {
        if level=0{align=center}{% allow multi-line text and set alignment
            align={@{}C{25mm}@{}},
        },
        rect,
        draw,
        edge path={
            \noexpand\path [draw, \forestoption{edge}] (!u.parent anchor) -- +(0,-7.5mm) -| (.child anchor)\forestoption{edge label};
          },
        l sep=5mm,
        align=center,
        edge+={ultra thick, rounded corners=2pt},
        ultra thick,
        inner color=white,
        outer color=white,
        rounded corners=2pt,
        drop shadow,
      }
      [AAAA
        [BBBB
          [CCCC]
          [DDDD]
          [EEEE]
        ]
        [FFFF
          [GGGG]
          [HHHH]
          [IIII]
        ]
        [JJJJ]
      ]
    \end{forest}}
    \end{document}

答案1

我做了一些调整,得到了这个结果。请注意,edge path现在仅为 定义level=1

\documentclass{article}
\usepackage[edges]{forest}
\usetikzlibrary{shadows}
\usepackage{array}
\newcolumntype{C}[1]{>{\centering}p{#1}}

\begin{document}
\scalebox{0.6}{
\forestset{%
  rect/.append style={rectangle, rounded corners=2pt},
  dir tree switch/.style args={at #1}{%
    for tree={
      fit=rectangle,
    },
    where level=#1{
      for tree={
        folder,
        grow'=0,
      },
      delay={child anchor=north},
    }{},
    before typesetting nodes={
      for tree={
        content/.wrap value={\strut ##1},
      },
      if={isodd(n_children("!r"))}{
        for nodewalk/.wrap pgfmath arg={{fake=r,n=##1}{calign with current edge}}{int((n_children("!r")+1)/2)},
      }{},
    },
  },
}


\begin{forest}
dir tree switch=at 1,
  for tree=
  {
    if level=1{align=center,
            edge path={
         \noexpand\path [draw, \forestoption{edge}] (!u.parent anchor) -- +(0,-7.5mm) -| (.child anchor)\forestoption{edge label};
      },
      }{% allow multi-line text and set alignment
        align={@{}C{25mm}@{}
        },
    },
    rect,
    draw,
    l sep=5mm,
    align=center,
    edge+={ultra thick, rounded corners=2pt},
    ultra thick,
    inner color=white,
    outer color=white,
    rounded corners=2pt,
    drop shadow,
  }
  [AAAA
    [BBBB
      [CCCC]
      [DDDD]
      [EEEE]
    ]
    [FFFF
      [GGGG]
      [HHHH]
      [IIII]
    ]
    [JJJJ]
  ]
\end{forest}}
\end{document}

在此处输入图片描述

相关内容