![如何使用多列(小页面)延续“森林”](https://linux22.com/image/361742/%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8%E5%A4%9A%E5%88%97%EF%BC%88%E5%B0%8F%E9%A1%B5%E9%9D%A2%EF%BC%89%E5%BB%B6%E7%BB%AD%E2%80%9C%E6%A3%AE%E6%9E%97%E2%80%9D.png)
我使用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}