![按列绘制森林中目录的第一级](https://linux22.com/image/452367/%E6%8C%89%E5%88%97%E7%BB%98%E5%88%B6%E6%A3%AE%E6%9E%97%E4%B8%AD%E7%9B%AE%E5%BD%95%E7%9A%84%E7%AC%AC%E4%B8%80%E7%BA%A7.png)
基于此例子,我正在尝试将文件夹结构的第一级移动到彼此旁边(因为我有 4 个包含大量文件的文件夹)。
到目前为止,我尝试过这个,但我卡在了下级文件夹的缩进上。我该如何像目录树一样对齐它们?
\documentclass{scrartcl}
\usepackage[edges]{forest}
\usetikzlibrary{shadows,arrows.meta}
\definecolor{folderbg}{RGB}{124,166,198}
\definecolor{folderborder}{RGB}{110,144,169}
\newlength\Size
\setlength\Size{4pt}
\tikzset{%
folder/.pic={%
\filldraw [draw=folderborder, top color=folderbg!50, bottom color=folderbg] (-1.05*\Size,0.2\Size+5pt) rectangle ++(.75*\Size,-0.2\Size-5pt);
\filldraw [draw=folderborder, top color=folderbg!50, bottom color=folderbg] (-1.15*\Size,-\Size) rectangle (1.15*\Size,\Size);
},
file/.pic={%
\filldraw [draw=folderborder, top color=folderbg!5, bottom color=folderbg!10] (-\Size,.4*\Size+5pt) coordinate (a) |- (\Size,-1.2*\Size) coordinate (b) -- ++(0,1.6*\Size) coordinate (c) -- ++(-5pt,5pt) coordinate (d) -- cycle (d) |- (c) ;
},
}
\forestset{%
declare autowrapped toks={pic me}{},
pic dir tree/.style={%
for tree={%
folder,
font=\ttfamily,
grow'=0,
directory,
fit=band,
},
before typesetting nodes={%
for tree={%
edge label+/.option={pic me},
},
},
},
pic me set/.code n args=2{%
\forestset{%
#1/.style={%
inner xsep=2\Size,
pic me={pic {#2}},
}
}
},
pic me set={directory}{folder},
pic me set={file}{file},
}
\begin{document}
\begin{forest}
pic dir tree,
where level=0{}{
directory,
},
where level=1{}{
file,
},
[Level 0,grow'=270,
[Level 1,grow'=0,forked edges,
[Level 2forked edges,
[Level 3]
[Level 3]
]
[Level 2]
]
[Level 1,grow'=0,
[Level 2,grow'=0,
]
[Level 2
]
[Level 2, file
]
]
[Level 1
[Level 2]
[Level 2]
]
[Level 1
]
]
\end{forest}
\end{document}
答案1
减少书法风格(如果需要,可以使用适当的 Ti钾Z 库 (Z library)pic dir tree
会创建一棵具有目标结构的树。
与通常folder
涉及方向的变化一样,该方法在某些地方有点繁琐(更不用说黑客了)。
\documentclass[tikz,border=10pt]{standalone}
\usepackage[edges]{forest}
% ateb: https://tex.stackexchange.com/a/705158/ addaswyd o gwestiwn Baptiste: https://tex.stackexchange.com/q/650430/
\usetikzlibrary{shadows,arrows.meta}
\definecolor{folderbg}{RGB}{124,166,198}
\definecolor{folderborder}{RGB}{110,144,169}
\newlength\Size
\setlength\Size{4pt}
\tikzset{%
folder/.pic={%
\filldraw [draw=folderborder, top color=folderbg!50, bottom color=folderbg] (-1.05*\Size,0.2\Size+5pt) rectangle ++(.75*\Size,-0.2\Size-5pt);
\filldraw [draw=folderborder, top color=folderbg!50, bottom color=folderbg] (-1.15*\Size,-\Size) rectangle (1.15*\Size,\Size);
},
file/.pic={%
\filldraw [draw=folderborder, top color=folderbg!5, bottom color=folderbg!10] (-\Size,.4*\Size+5pt) coordinate (a) |- (\Size,-1.2*\Size) coordinate (b) -- ++(0,1.6*\Size) coordinate (c) -- ++(-5pt,5pt) coordinate (d) -- cycle (d) |- (c) ;
},
}
\forestset{%
declare autowrapped toks={pic me}{},
declare dimen={edge adjust}{0pt},
pic dir tree/.style={%
grow=-90,
for descendants={grow'=0},
for tree={%
folder,
font=\ttfamily,
if n children=0{file}{directory},
},
delay={%
for tree={%
edge label+/.option={pic me},
},
},
before drawing tree={x/.option=!1.x},
for children={%
before drawing tree={%
edge+/.process={Ow{!u.edge adjust}{shorten <=##1-5pt}},
},
before typesetting nodes={%
replace by={%
[,
delay={%
if n=1{%
edge+={shorten >=-7.5pt,shorten <=-7.5pt,very thick},
edge path'/.process={%
OORw3 {edge adjust}{!ul.edge adjust}{folder indent}
{%
([yshift=-##1+5pt,xshift=##3].parent anchor) -- ([yshift=-##2+5pt,xshift=##3]!ul.parent anchor)%
}%
},
}{%
no edge,
},
},
folder,
grow'=0,
edge adjust/.process={Odw2+P{n}{3pt}{##1*##2}},
s sep/.option=edge adjust,
before computing xy={l'=7.5pt},
append,
]%
},
},
},
},
/handlers/.pic me set/.code={%
\forestset{%
\pgfkeyscurrentpath/.style={%
inner xsep=2\Size,
pic me={pic {#1}},
},
}%
},
directory/.pic me set=folder,
file/.pic me set=file,
}
\begin{document}
\begin{forest}
pic dir tree,
[Level 0,
[Level 1,
[Level 2
[Level 3]
[Level 3]
]
[Level 2]
]
[Level 1,
[Level 2,
]
[Level 2
]
[Level 2
]
]
[Level 1
[Level 2]
[Level 2]
]
[Level 1
[]
]
]
\end{forest}
\end{document}