我从用户那里得到了这个代码贡萨洛·梅迪纳 这里看起来很棒,这正是我想要的。但是我想添加每个文件夹的描述,这可能是一个相当长的测试,例如下面的“配置”节点。
\documentclass[border=5pt]{standalone}
\usepackage{forest}
\definecolor{folderbg}{RGB}{124,166,198}
\definecolor{folderborder}{RGB}{110,144,169}
\def\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);
}
}
\begin{document}
\begin{forest}
for tree={
font=\ttfamily,
grow'=0,
child anchor=west,
parent anchor=south,
anchor=west,
calign=first,
inner xsep=7pt,
edge path={
\noexpand\path [draw, \forestoption{edge}]
(!u.south west) +(7.5pt,0) |- (.child anchor) pic {folder} \forestoption{edge label};
},
before typesetting nodes={
if n=1
{insert before={[,phantom]}}
{}
},
fit=band,
before computing xy={l=15pt},
}
[system
[config: this text is sooooo long oh not it won't fit in the page help me please
]
[lib
[Access
]
[Plugin
]
]
[templates
]
[tests
]
]
\end{forest}
\end{document}
我希望文本自动转到新行。
提前致谢!
答案1
您可以限制文本的宽度。例如使用 text width=8cm
\documentclass[border=5pt]{standalone}
\usepackage{forest}
\definecolor{folderbg}{RGB}{124,166,198}
\definecolor{folderborder}{RGB}{110,144,169}
\def\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);
}
}
\begin{document}
\begin{forest}
for tree={
font=\ttfamily,
text width=8cm,% added <<<<<<<<<<<<<<
grow'=0,
child anchor=west,
parent anchor=south,
anchor=west,
calign=first,
inner xsep=7pt,
edge path={
\noexpand\path [draw, \forestoption{edge}]
(!u.south west) +(7.5pt,0) |- (.child anchor) pic {folder} \forestoption{edge label};
},
before typesetting nodes={
if n=1
{insert before={[,phantom]}}
{}
},
fit=band,
before computing xy={l=15pt},
}
[system
[config: this text is sooooo long oh not it won't fit in the page help me please
]
[lib
[Access
]
[Plugin
]
]
[templates
]
[tests
]
]
\end{forest}
\end{document}
后续问题后更新。
这是另一种方法:
\documentclass[border=5pt]{standalone}
\usepackage{forest}
\definecolor{folderbg}{RGB}{124,166,198}
\definecolor{folderborder}{RGB}{110,144,169}
\def\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);
}
}
\begin{document}
\begin{forest}
for tree={
font=\ttfamily,
grow'=0,
child anchor=west,
parent anchor=south,
anchor=west,
calign=first,
inner xsep=7pt,
edge path={
\noexpand\path [draw, \forestoption{edge}]
(!u.south west) +(7.5pt,0) |- (.child anchor) pic {folder} \forestoption{edge label};
},
before typesetting nodes={
if n=1
{insert before={[,phantom]}}
{}
},
fit=band,
before computing xy={l=15pt},
}
[system
[config: \parbox{7cm}{this text is sooooo long oh not it won't fit in the page help me please}% changed
]
[lib
[Access
]
[Plugin
]
]
[templates
]
[tests
]
]
\end{forest}
\end{document}