如何在森林中聚合和发散节点?

如何在森林中聚合和发散节点?

我想要一个这样的结构- 在此处输入图片描述

然而,我可以想到这一点-

在此处输入图片描述

我想要“A Concept”、“B Concept”、“C Concept”中出现“P”、“Q”、“R”、“S”。我该怎么做?我的代码如下-

    \forestset{
  not a tree/.style={
    forked edges,
    for tree={
    grow'=east,
      edge+={thick, -Stealth},
      thick,
      draw=darkgray, thick, rounded corners, top color=gray!5, bottom color=gray!15, edge+={thick},
      font=\sffamily,
      align=c, 
      parent anchor=children,
      child anchor=parent,
      anchor=parent,
      l sep'+=10pt,
      fork sep'+=5pt,
      tier/.option=level
    },
    },
  }

\begin{forest}
  not a tree,
  [Instances
    [A\\ Concept]
    [B\\ Concepts]
    [C\\ Concepts]
    [[P
                [P1]
                [P2]
                [P3]
                [P4]
        ]
    [Q
        [Q1]
        [Q2]
            ]          
    [R
        [R1]
        [R2]
            ]
    [S
            ]
    ]
]
\end{forest}

答案1

您可以在节点处调整fork sep和,然后从节点到节点画一条线。如果为树设置和,则可以保持间距均匀。l sepB\drawACl sepfork sep

在此处输入图片描述

\documentclass{article}

\usepackage{forest}
\useforestlibrary{edges}
\usetikzlibrary{arrows.meta}

\begin{document}

\begin{forest}
  forked edges,
    for tree={
      grow'=east,
      edge={thick, -Stealth},
      thick,
      draw=darkgray, thick, rounded corners, top color=gray!5, bottom color=gray!15, edge+={thick},
      font=\sffamily,
      align=c,
      anchor=parent,
      l sep=10mm,
      fork sep=5mm,
      tier/.option=level
    }
[Instances
  [A\\ Concept, name=A]
  [B\\ Concept, l sep+=5mm, for children={fork sep+=5mm}
    [P
      [P1]
      [P2]
      [P3]
      [P4]
    ]
    [Q       [Q1]
       [Q2]
    ]          
    [R
       [R1]
       [R2]
    ]
    [S
]
  ]
  [C\\ Concept, name=C]
]
\draw[thick] (A.east)--++(.5,0)|-(C);  
\end{forest}

\end{document}

答案2

在此处输入图片描述

这更像是一种强力解决方案,而不是一种连接forest包内节点的方法,但它确实有效。我不知道如何去掉小圆圈,这超出了我目前的知识范围tikzforest希望其他人能够用合适的forest版本来回答。

\documentclass[tikz,border=1.414mm]{standalone}

\usepackage[edges]{forest}
\usetikzlibrary{arrows.meta,calc}

\begin{document}

 \forestset{
 not a tree/.style={
    forked edges,
    for tree={
    grow'=east,
      edge+={thick, -Stealth},
      thick,
      draw=darkgray, thick, rounded corners, top color=gray!5, bottom color=gray!15, edge+={thick},
      font=\sffamily,
      align=c, 
      parent anchor=children,
      child anchor=parent,
      anchor=parent,
      l sep'+=10pt,
      fork sep'+=5pt,
      tier/.option=level
    },
    },
  }

\begin{forest}
  not a tree,
  [Instances
    [A\\ Concept,name=A]{\draw[-,thick] (A) -- ($(A)+(1.4,0)$);}
    [B\\ Concepts,name=B
            [[P
                [P1][P2][P3][P4]]
            [Q
                [Q1][Q2]]
            [R
                [R1][R2]]
        [S]
        ]
    ]
    [C\\ Concepts,name=C]{\draw[-,thick] (C) -- ($(C)+(1.4,0)$); \draw[-,thick] ($(C)+(1.4,0)$) -- ($(A)+(1.4,0)$);}
]
\end{forest}
\end{document}

相关内容