2

A while back, cfr kindly answered my question here. But I have some issues.

1) I want to be able to insert vertical dots at any ‘level’ of the forest tree

(Ref: cfr’s first comment)

I want something like this:

enter image description here

I tried

 \begin{forest} pic dir tree, pic root, for tree={% folder icons by default; override using file for file icons directory, }, [system,extensible edge [config ] [lib, extend [file.txt, file, extend ] [file, file] ] ] \end{forest} 

with cfr’s MWE but it gave

enter image description here

2) How to adapt the code so that it works with rounded corners

(Ref: cfr’s second comment)

When we use for tree={edge=rounded corners}, as in the following MWE, we have extraneous white space, which the removal of |- !u.child anchor seems to solve:

 \documentclass[border=10pt,multi,tikz]{standalone} % ateb: https://tex.stackexchange.com/a/754955/ \usepackage[edges]{forest} \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, sharp corners] (-1.05*\Size,0.2\Size+5pt) rectangle ++(.75*\Size,-0.2\Size-5pt); \filldraw [draw=folderborder, top color=folderbg!50, bottom color=folderbg, sharp corners] (-1.15*\Size,-\Size) rectangle (1.15*\Size,\Size); }, file/.pic={% \filldraw [draw=folderborder, top color=folderbg!5, bottom color=folderbg!10, sharp corners] (-\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 boolean register={pic root}, pic root=0, pic dir tree/.style={% for tree={% folder, font=\ttfamily, grow'=0, }, before typesetting nodes={% for tree={% edge label+/.option={pic me}, edge=rounded corners, }, if pic root={ tikz+={ \pic at ([xshift=\Size].west) {folder}; }, align={l} }{}, }, }, 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}, declare toks={real siblings}{}, extensible edge/.style={% delay={% prepend={[\strut, delay={% do dynamics, temptoksa=, for following siblings={% if temptoksa={}{}{% temptoksa+={,}, }, temptoksa+/.option=name, }, real siblings/.register=temptoksa, folder, grow'=0, before computing xy={% l'=0pt, s'=-15pt, }, delay n=2{% split option={real siblings}{,}{append}, }, }, edge path'={% (!u.parent anchor) ++(\foresteregister{folder indent},0pt) -- ++(0pt,-5pt) edge [dotted] ([xshift=\foresteregister{folder indent}].parent anchor) }, ]}, }, }, extend/.style={% delay={% append={[\strut, folder, grow'=0, before computing xy={% l'=0pt, s'=-15pt, }, if n children=0{% before drawing tree={% delay={% y/.min={>O{y}}{parent,descendants}, }, }, }{}, edge path'={% (!uu.parent anchor |- !u.child anchor) ++(\foresteregister{folder indent},0pt) coordinate (a) -- ([yshift=15pt].parent anchor -| a) edge [dotted] (.parent anchor -| a) }, ]}, }, }, } \begin{document} \begin{forest} pic dir tree, pic root, for tree={% folder icons by default; override using file for file icons directory, }, [system [config ] [lib [Access ] [Plugin ] [file.txt, file ] ] ] \end{forest} \begin{forest} pic dir tree, pic root, for tree={% folder icons by default; override using file for file icons directory, }, [system, extensible edge, [config ] [lib [Access ] [Plugin ] [file.txt, file ] ] ] \end{forest} \begin{forest} pic dir tree, pic root, for tree={% folder icons by default; override using file for file icons directory, }, [system [config ] [lib, extend [Access ] [Plugin ] [file.txt, file,extend ] ] ] \end{forest} \begin{forest} pic dir tree, pic root, for tree={% folder icons by default; override using file for file icons directory, }, [system,extensible edge [config ] [lib, extend [Access ] [Plugin ] [file.txt, file, extend ] ] ] \end{forest} \end{document} 

enter image description here

1
  • thank you for splitting out your followup. but this is two questions and probably should be split also. (this may not be obvious, but the rounded corner thing is not trivial in this specific case. finding the right tweak with folder isn't simple.) it can be done, but it is very different from the structural question. Commented 21 hours ago

1 Answer 1

3

I wrote this in response to the earlier question, but never posted it as I did not consider it reasonable to edit that question after answers were posted in ways which significantly altered the requirements.

You have really asked two questions:

  1. how to modify the styles in my earlier answer to insert dots in additional places;
  2. how to make the styles work with rounded corners.

This answer addresses the first of these questions.

In general, I do not recommend the use of rounded corners in forest. Sometimes it works for special effects. More often, it is painful to implement and fragile to use.

In any case, IMHO, the results usually look less professional, fussier and more cluttered. Fine for Christmas trees. Not so much for professional publications.

The first question is far more interesting ....

\documentclass[border=10pt,multi,tikz]{standalone} % ateb: https://tex.stackexchange.com/a/754955/ % ateb: https://tex.stackexchange.com/a/755401/ \usepackage[edges]{forest} \definecolor{folderbg}{RGB}{124,166,198} \definecolor{folderborder}{RGB}{110,144,169} \newlength\Size \setlength\Size{4pt} \tikzset{% folder/.pic={% \filldraw [draw=folderborder, sharp corners, top color=folderbg!50, bottom color=folderbg] (-1.05*\Size,0.2\Size+5pt) rectangle ++(.75*\Size,-0.2\Size-5pt); \filldraw [draw=folderborder, sharp corners, top color=folderbg!50, bottom color=folderbg] (-1.15*\Size,-\Size) rectangle (1.15*\Size,\Size); }, file/.pic={% \filldraw [draw=folderborder, sharp corners, 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 boolean register={pic root}, pic root=0, declare keylist={additional edge options}{}, pic dir tree/.style={% for tree={% folder, font=\ttfamily, grow'=0, }, before typesetting nodes={% for tree={% edge label+/.option={pic me}, % edge+/.option=additional edge options, % edge=rounded corners, }, if pic root={ tikz+={ \pic at ([xshift=\Size].west) {folder}; }, align={l} }{}, }, }, 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}, declare toks={real siblings}{}, extensible edge/.style={% delay={% if n children=0{% before computing xy={% for current and following siblings={% s'+=-10pt, }, }, if n=1{% edge path'={% (!u.parent anchor) ++(\foresteregister{folder indent},0pt) coordinate (a) -- ([yshift=20pt].child anchor -| a) edge [dotted] ++(0pt,-10pt) ++(0pt,-10pt) |- (.child anchor) }, }{% edge path'={% (!u.parent anchor |- !p.child anchor) ++(\foresteregister{folder indent},0pt) coordinate (a) -- ([yshift=20pt].child anchor -| a) edge [dotted] ++(0pt,-10pt) ++(0pt,-10pt) |- (.child anchor) }, }, for following siblings={% edge path'={% (!u.parent anchor |- !p.child anchor) ++(\foresteregister{folder indent},0pt) |- (.child anchor) }, }, }{% prepend={[\strut, delay={% do dynamics, temptoksa=, for following siblings={% if temptoksa={}{}{% temptoksa+={,}, }, temptoksa+/.option=name, }, real siblings/.register=temptoksa, folder, grow'=0, before computing xy={% l'=0pt, s'=-15pt, }, delay n=2{% split option={real siblings}{,}{append}, }, }, edge path'={% (!u.parent anchor) ++(\foresteregister{folder indent},0pt) -- ++(0pt,-5pt) edge [dotted] ([xshift=\foresteregister{folder indent}].parent anchor) }, ]}, }, }, }, extend/.style={% delay={% append={[\strut, folder, grow'=0, before computing xy={% l'=0pt, s'=-15pt, }, if n children=0{% before drawing tree={% delay={% y/.min={>O{y}}{parent,descendants}, }, }, }{}, edge path'={% (!uu.parent anchor |- !u.child anchor) ++(\foresteregister{folder indent},0pt) coordinate (a) -- ([yshift=15pt].parent anchor -| a) edge [dotted] (.parent anchor -| a) }, ]}, }, }, } \begin{document} \begin{forest} pic dir tree, pic root, for tree={% folder icons by default; override using file for file icons directory, }, [system [config ] [lib [Access ] [Plugin ] [file.txt, file ] ] ] \end{forest} \begin{forest} pic dir tree, pic root, for tree={% folder icons by default; override using file for file icons directory, }, [system, extensible edge, [config ] [lib [Access ] [Plugin ] [file.txt, file ] ] ] \end{forest} \begin{forest} pic dir tree, pic root, for tree={% folder icons by default; override using file for file icons directory, }, [system [config ] [lib, extend [Access ] [Plugin ] [file.txt, file,extend ] ] ] \end{forest} \begin{forest} pic dir tree, pic root, for tree={% folder icons by default; override using file for file icons directory, }, [system,extensible edge [config ] [lib,extend [Access ] [Plugin ] [file.txt, file,extend ] ] ] \end{forest} \begin{forest} pic dir tree, pic root, for tree={% folder icons by default; override using file for file icons directory, }, [system,extensible edge [config ] [lib,extend [Access, extensible edge ] [Plugin, extensible edge ] [file.txt, file,extend ] ] ] \end{forest} \begin{forest} pic dir tree, pic root, for tree={% folder icons by default; override using file for file icons directory, additional edge options=rounded corners, }, [system,extensible edge [config ] [lib,extend [Access, extensible edge ] [Plugin, extensible edge ] [file.txt, file,extend ] ] ] \end{forest} \end{document} 

more dots in more places

Note that adding rounded corners breaks the lines because we have to prevent each child drawing a full edge from its parent. By default all edges are drawn, even where they overlap. So each sub-directory has an edge drawn from its parent. If we have dots there, we don't want the following siblings to do this, as solid lines will just draw over the dots. So we have to draw a shorter edge. If rounded corners is used, this creates a gap.

You can draw over that gap, but that's piecemeal and ad hoc. To do it properly, you have to know how large the value used for rounding is and to take account of where the parent's anchors are, the direction of growth etc. Generally, you can use forest anchors for this, which abstract from the gory details. But with folder it is not so easy.

1
  • Between system and the first vertical dot directly below it, there is a vertical line; between the third vertical dot and config is another vertical line. Is it possible to adjust these lines to be of equal length? Commented 2 mins ago

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.