如何使用多列(小页面)延续“森林”

如何使用多列(小页面)延续“森林”

我使用forest来说明文件夹结构。由于树的长度,我想将其分成两个“列”。为此,我使用了两个迷你页面。

为了证明两个“子树”共享同一个根,我想将第一个(左)小页面的根延续到最后。

这可能吗?

下图以黑色显示当前树,以红色显示我正在谈论的线: 在此处输入图片描述

这是我的 MWE:

\documentclass{article}
\usepackage{forest}
\usepackage{fontawesome}

\begin{document}


\begin{figure}
\centering
\begin{minipage}{.5\textwidth}
  \centering
  \begin{forest}
  for tree={
    font=\normalfont,
    grow'=0,
    child anchor=west,
    parent anchor=south,
    anchor=west,
    calign=first,
    edge path={
      \noexpand\path [draw, \forestoption{edge}]
      (!u.south west) +(7.5pt,0) |- node[fill,inner sep=1.25pt] {} (.child anchor)\forestoption{edge label};
    },
    before typesetting nodes={
      if n=1
        {insert before={[,phantom]}}
        {}
    },
    fit=band,
    before computing xy={l=15pt},
  }
[root
  [\faFolderOpenO ~One
    [\faFolderOpenO ~OneOne]
    [\faFolderOpenO ~OneTwo
      [\faFolderOpenO ~OneTwoOne]
      [\faFolderOpenO ~OneTwoTwo]
    ]
  ]
]
\end{forest}
\end{minipage}% 
\begin{minipage}{.5\textwidth}
  \centering
 \begin{forest}
  for tree={
    font=\normalfont,
    grow'=0,
    child anchor=west,
    parent anchor=south,
    anchor=west,
    calign=first,
    edge path={
      \noexpand\path [draw, \forestoption{edge}]
      (!u.south west) +(7.5pt,0) |- node[fill,inner sep=1.25pt] {} (.child anchor)\forestoption{edge label};
    },
    before typesetting nodes={
      if n=1
        {insert before={[,phantom]}}
        {}
    },
    fit=band,
    before computing xy={l=15pt},
  }
[
  [\faFolderOpenO ~Two
    [\faFolderOpenO ~TwoOne]
  ]
  [\faFolderOpenO ~Three
    [\faFolderOpenO ~ThreeOne]
  ]
  [\faFolderOpenO ~Four]
]
\end{forest}
\end{minipage}

\caption{Captiontext}
\end{figure}

\end{document}

答案1

有多种方法可以让森林分裂树。但是,minipage正如您所说,在这种情况下,这可能是最简单的策略。

\documentclass{article}
\usepackage[edges]{forest}
\usepackage{fontawesome}
\forestset{%
  declare boolean register={my dir tree cont},
  my dir tree cont=false,
  my dir tree/.style={
    for tree={
      grow'=0,
      folder,
      edge label={node [fill, inner sep=1.25pt, midway] {} },
    },
    delay={
      for nodewalk={
        if my dir tree cont={fake=r}{r},
        descendants
      }{content/.wrap value={\faFolderOpenO ~##1}},
      if my dir tree cont={}{
        tikz+={
          \draw (!r.parent anchor |- !r1.child anchor) ++(\foresteregister{folder indent},0) coordinate (a) -- (current bounding box.south -| a) node [below, font=\footnotesize, gray] {cont.};
        },
      },
    },
  },
}
\begin{document}
\begin{minipage}{.5\textwidth}
  \centering
  \begin{forest}
    my dir tree
    [root
      [One
        [OneOne]
        [OneTwo
          [OneTwoOne]
          [OneTwoTwo]
        ]
      ]
    ]
\end{forest}
\end{minipage}% 
\begin{minipage}{.5\textwidth}
  \centering
  \begin{forest}
    my dir tree,
    my dir tree cont,
    [
      [Two
        [TwoOne]
      ]
      [Three
        [ThreeOne]
      ]
      [Four]
    ]
\end{forest}
\end{minipage}
\end{document}

分割<code>森林</code>树木

相关内容