1

I have a directory tree that almost looks like this:

Sample directory tree

The above image is what I am trying to achieve. Here's my one which I took help and slightly modified from Making a (simple) directory tree

My directory tree

I know I should have made a bit more effort, but I am not that of a pro when it comes to making charts especially related to complex trees. Here what I am looking for is a way to make background color of each nodes gray except the primary (or root) node. The primary node should have box as shown in the image. Also I am looking for a way to arbitrarily modify the node to have boxes like the primary node as shown at the middle and bottom of the image. Also that the small box at the left should have a minus sign (expand form). The caption at the top is optional, and the lines at the end of the image are to be ignored. It doesn't matter which packages are to be used as long as they are convenient.

UPDATE

I managed to improve my picture a bit by using fill, inner sep, and s sep as well as editing the node in edge path to mimic the expand form. Now all I need a little bit help on making the edge path similar to the first image.

My picture 2

Here's my code:

\documentclass[border=5pt]{standalone}
\usepackage{forest}
\usepackage{xcolor}

\definecolor{mygray}{RGB}{224,224,224} \begin{document}

\begin{forest} for tree={ font=\sffamily, if level=0 {fill=white,draw=black} {fill=mygray,draw=black}, grow'=0, child anchor=west, parent anchor=south, anchor=west, calign=first, inner xsep= 15pt, s sep=15pt, edge path={ \noexpand\path [draw, \forestoption{edge}] (!u.south west) +(7.5pt,0) |- node[fill=white,draw,inner sep=1pt,align=center] {$-$} (.child anchor)\forestoption{edge label}; }, before typesetting nodes={ if n=1 {insert before={[,phantom]}} {} }, fit=band, before computing xy={l=35pt}, } [R1SC4000R - Processor for Service [SETUIXNAM] [{QC2UTIL1,R1SC3000ER,DOCERROR}] [STEPCONDITION [LOKUPUIX [R1SB8000R - Handle User Index\quad UIX,fill=white] ] [{GETFROMUIX,GETFROMUIX}] [{GETFROMUIX,GETFROMUIX}] ] [ONESUB [{QC2UTIL1,R1SC3000ER,DOCERROR}] [UIXPERM2TEMP [{GETFROMUIX,GETFROMUIX}] [CLRUIX [R1SB8000R - Handle User Index\quad UIX,fill=white] ] ] ] ] \end{forest}

\end{document

SolidMark
  • 1,389

1 Answers1

3

If I get this correctly, there are two issues here. First, the - node should only appear when the subfolder has children. Second, the edges to other children should not draw over the - nodes.

For the first issue, we can use the if n children conditional. If there are no children, we set up a simple edge path, without the node; otherwise, the one with the framed -.

The second issue can be solved by changing the order in which the edges are drawn; the edges of the children must be drawn starting at the last child. This can be setting the draw tree edges processing order nodewalk style (see section 3.4.3 of the manual) to tree reversed (section 3.8.3).

Here's the complete updated code:

\documentclass[border=5pt]{standalone}
\usepackage{forest}
\usepackage{xcolor}

\definecolor{mygray}{RGB}{224,224,224} \begin{document}

\begin{forest} draw tree edges processing order/.nodewalk style=tree reversed, for tree={ font=\sffamily, if level=0 {fill=white,draw=black} {fill=mygray,draw=black}, grow'=0, child anchor=west, parent anchor=south, anchor=west, calign=first, inner xsep= 15pt, s sep=15pt, if n children=0{ edge path={ \noexpand\path [draw, \forestoption{edge}] (!u.south west) +(7.5pt,0) |- (.child anchor)\forestoption{edge label}; }, }{ edge path={ \noexpand\path [draw, \forestoption{edge}] (!u.south west) +(7.5pt,0) |- node[fill=white,draw,inner sep=1pt,align=center] {$-$} (.child anchor)\forestoption{edge label}; }, }, before typesetting nodes={ if n=1 {insert before={[,phantom]}} {} }, fit=band, before computing xy={l=35pt}, } [R1SC4000R - Processor for Service [SETUIXNAM] [{QC2UTIL1,R1SC3000ER,DOCERROR}] [STEPCONDITION [LOKUPUIX [R1SB8000R - Handle User Index\quad UIX,fill=white] ] [{GETFROMUIX,GETFROMUIX}] [{GETFROMUIX,GETFROMUIX}] ] [ONESUB [{QC2UTIL1,R1SC3000ER,DOCERROR}] [UIXPERM2TEMP [{GETFROMUIX,GETFROMUIX}] [CLRUIX [R1SB8000R - Handle User Index\quad UIX,fill=white] ] ] ] ] \end{forest}

\end{document}

enter image description here

UPDATE: draw the - to the left of the root as well

In my opinion, it is best to do this manually: shift the root a bit to the right, and put the - to the left of it. The problem is that the children of the root connect to the root node; the solution: generalize the edge path assignment to support arbitrary shifts, and apply it to the children of the root separately.

\documentclass[border=5pt]{standalone}
\usepackage{forest}
\usepackage{xcolor}

\definecolor{mygray}{RGB}{224,224,224} \begin{document}

\begin{forest} draw tree edges processing order/.nodewalk style=tree reversed, my edge path/.style={ edge path={ \noexpand\path [draw, \forestoption{edge}] (!u.south west) #1 |- (.child anchor)\forestoption{edge label}; }, }, my edge path with node/.style={ edge path={ \noexpand\path [draw, \forestoption{edge}] (!u.south west) #1 |- node[fill=white,draw,inner sep=1pt,align=center] {$-$} (.child anchor)\forestoption{edge label}; }, }, for tree={ font=\sffamily, if level=0 {fill=white,draw=black} {fill=mygray,draw=black}, grow'=0, child anchor=west, parent anchor=south, anchor=west, calign=first, inner xsep= 15pt, s sep=15pt, if n children=0{ my edge path={+(7.5pt,0)}, }{ my edge path with node={+(7.5pt,0)}, }, before typesetting nodes={ if n=1 {insert before={[,phantom]}} {} }, fit=band, before computing xy={l=35pt}, }, % The root will be shifted to the right, so the children need to connect to a % point a bit more to the left of it. for children={ if n children=0{ % We need 2.5pt (determined by visual inspection) to compensate for the % height difference between the root and its - box. my edge path with node={+(-15pt,+2.5pt)} }{ my edge path={+(-15pt,+2.5pt)} } }, % Shift the root to the right. before drawing tree={ x+=7.5pt+15pt, }, % Draw the - node on the left side of the root. tikz+={ \node (root-) at ([xshift=-15pt].west) [fill=white,draw,inner sep=1pt] {$-$}; \draw (root-) -- (!r.west); }, [R1SC4000R - Processor for Service [SETUIXNAM] [{QC2UTIL1,R1SC3000ER,DOCERROR}] [STEPCONDITION [LOKUPUIX [R1SB8000R - Handle User Index\quad UIX,fill=white] ] [{GETFROMUIX,GETFROMUIX}] [{GETFROMUIX,GETFROMUIX}] ] [ONESUB [{QC2UTIL1,R1SC3000ER,DOCERROR}] [UIXPERM2TEMP [{GETFROMUIX,GETFROMUIX}] [CLRUIX [R1SB8000R - Handle User Index\quad UIX,fill=white] ] ] ] ] \end{forest}

\end{document}

the updated result

  • I was trying to fix these two issues really. For the first issue, I was trying to bring the - node to the west of a parent subfolder. I didn't have an inch of idea to fix it. As for the second issue, I thought filling node white would solve the problem, but it did not. Your solution really counts as a possible answer. If possible, could you update your answer to include the - beside the root node to show that it is expandable? That's ok if not possible – SolidMark Sep 14 '21 at 09:51
  • Doable, if on the manual side. By the way, I love how you created the folder structure using the phantom node! It seems more robust than the method currently deployed by folder, I might use your idea in the following release. – Sašo Živanović Sep 14 '21 at 10:28