BlogDiagrams
Foldersetup

Description

The code above is a LaTeX document that creates a directory tree diagram using the Forest package. The tree is defined using the forest environment and each node in the tree is represented by a folder icon, which is defined by the \myfolder command. The folders are colored in blue by default, but can be changed to green by passing the optional argument [fgreen] to the \myfolder command. The contents of the folders are represented by child nodes in the tree, and each child node is also a folder icon. The tree is arranged such that each folder node is aligned to the left and its child nodes are indented to the right. The code also defines the fblue and fgreen colors using the xcolor package and the tikzpicture environment is used to draw the folder icon.

Keywords

forest, tikzpicture, scope, filldraw, rounded corners, top color, bottom color, child anchor, parent anchor, calign, edge, edge path, phantom, fit, s sep, l.

Source Code

BlogDiagrams

\documentclass[border=10pt]{standalone}
\usepackage{forest}
 
\definecolor{fblue}{RGB}{92,144,192}
\definecolor{fgreen}{RGB}{34,162,70}
 
\newcommand\myfolder[2][fblue]{%
\begin{tikzpicture}[overlay]
\begin{scope}[xshift=20pt]
\filldraw[rounded corners=1pt,fill=#1,draw=white,double=black]
  (-23pt,10pt) -- ++(3pt,5pt) -- ++(18pt,0pt) -- ++(40:3pt) -- ++(9pt,0pt) -- ++(-40:3pt)
  -- (20pt,15pt) -- (23pt,10pt) -- cycle;
\filldraw[rounded corners,draw=white,double=black,top color=#1,bottom color=#1!30]
  (-22pt,-12pt) -- ++(44pt,0pt) -- (25pt,12pt) coordinate (topr) -- ++(-50pt,0pt) coordinate (topl) -- cycle;
\end{scope}  
\end{tikzpicture}%
\makebox[35pt]{\raisebox{-3pt}{{\ttfamily/#2}}}%
}
 
\begin{document}
 
\begin{forest}
  for tree={
    font=\sffamily,
    minimum height=0.75cm,
    rounded corners=4pt,
    grow'=0,
    inner ysep=8pt,
    child anchor=west,
    parent anchor=south,
    anchor=west,
    calign=first,
    edge={rounded corners},
    edge path={
      \noexpand\path [draw, \forestoption{edge}]
      (!u.south west) +(12.5pt,0) |- (.child anchor)\forestoption{edge label};
    },
    before typesetting nodes={
      if n=1
        {insert before={[,phantom,minimum height=18pt]}}
        {}
    },
    fit=band,
    s sep=12pt,
    before computing xy={l=25pt},
  }
[\myfolder{}
  [\myfolder{jhunt}]
  [\myfolder{dev}
  	[{\myfolder[fgreen]{bchain}}]
  	[{\myfolder[fgreen]{other}}]
  ]
  [{\myfolder[fgreen]{games}}
    [{\myfolder[fgreen]{vns}}]
    [{\myfolder[fgreen]{other}}]
  ]
  [\myfolder{music}]
  [\myfolder{other}]
]
\end{forest}
 
\end{document}
Deploy to Overleaf