6

I need to create a figure like the following one image

An image shows a directory tree using folders icons. What do you suggest me to do?

  • Have you looked at the forest package? – ajeh Nov 11 '14 at 21:41
  • @ajeh I have just looked at it. It is nice but it does not permit to write inside folders icons – Germano Massullo Nov 11 '14 at 21:57
  • Your question leaves all the effort to our community, even typing the essentials of a TeX document such as \documentclass{}...\begin{document} etc. As it is, most of our users will be very reluctant to touch your question, and you are left to the mercy of our procrastination team who are very few in number and very picky about selecting questions. You can improve your question by adding a minimal working example (MWE) that more users can copy/paste onto their systems to work on. If no hero takes the challenge we might have to close your question. – cfr Nov 11 '14 at 22:24
  • What do you mean? Do you really think there is going to be a package which has a write-inside-folder-icons among its default options? I think you will wait a long time for a solution in that case ;). – cfr Nov 11 '14 at 22:25
  • By the way, /bin is now a symbolic link on most systems. (Those which follow the newer standards for the hierarchy. Admittedly, it is a mixed bag at the moment.) Likewise, /media is no longer in the top level on many systems. – cfr Nov 11 '14 at 22:29
  • @cfr concerning /bin that is true, but for /media... this is a # ls / on Fedora 21 http://paste.fedoraproject.org/150158/17663141/ – Germano Massullo Nov 12 '14 at 18:45
  • I think fedora has incompletely implemented the new hierarchy though I'm not sure of the details. – cfr Nov 12 '14 at 18:50

2 Answers2

16

Here's one possibility using forest and TikZ:

enter image description here

The code:

\documentclass{article}
\usepackage{forest}

\definecolor{fblue}{RGB}{92,144,192}
\definecolor{fgreen}{RGB}{34,162,70}

\newcommand\myfolder[2][fblue]{%
\begin{tikzpicture}[overlay]
  \draw[fill=#1!82!black] 
    (-20pt,14pt) -- 
    (-17pt,17pt) --
    (-1pt,17pt) --
    (1pt,19pt) --
    (12pt,19pt) --
    (14pt,17pt) --
    (17pt,17pt) --
    (20pt,14pt) -- cycle;
  \draw[line width=0.75pt,white] 
    (-18.5pt,14pt) -- 
    (-15.5pt,16.5pt) --
    (0.5pt,16.5pt) --
    (2pt,18.3pt) --
    (10.5pt,18.3pt) --
    (12.5pt,16.5pt) --
    (15.5pt,16.5pt) --
    (18.5pt,14pt) -- cycle;
  \draw[rounded corners,top color=#1,bottom color=#1!30] 
    (-23pt,14pt) -- 
    (23pt,14pt) --
    (21pt,-14pt) --
    (-21pt,-14pt) -- cycle;
  \draw[rounded corners,line width=1pt,white] 
    (-22pt,13pt) -- 
    (22pt,13pt) --
    (20pt,-13pt) --
    (-20pt,-13pt) -- cycle;
\end{tikzpicture}%
\makebox[0pt]{\raisebox{-3pt}{{\ttfamily\small/#2}}}%
}


\begin{document}

\begin{forest}
for tree={
  parent anchor=south,
  child anchor=north,
  node options={inner sep=11pt},
  l sep=25pt,
  s sep=40pt,
} 
[\myfolder{}
  [\myfolder{bin}]
  [\myfolder{dev}]
  [{\myfolder[fgreen]{home}}
    [{\myfolder[fgreen]{anna}}]
    [{\myfolder[fgreen]{claudio}}]
  ]
  [\myfolder{media}]
  [\myfolder{mnt}]
  [\myfolder{usr}]
]
\end{forest}

\end{document}

The command \myfolder has one mandatory argument for the label of the folder and an optional argument for the color.

Gonzalo Medina
  • 505,128
4

Here's a forest solution:

\documentclass[tikz,border=5pt]{standalone}
\usepackage{forest}
\usetikzlibrary{shapes.geometric}
\begin{document}
  \tikzset{/forest,
    symlink/.append style={
      opacity=.25,
      text opacity=.5,
      before drawing tree={
        {tikz+={\draw [thick, -{>[]}] (!#1.west) ++(4pt,-1.5pt) arc (315:120:5pt);}}
      },
    },
  }
  \begin{forest}
    for tree={
      parent anchor=south,
      child anchor=north,
      trapezium,
      trapezium angle=95,
      rounded corners=2pt,
      draw,
      fill=blue!50,
    }
    [/
      [/bin, symlink
      ]
      [/boot
      ]
      [/dev
      ]
      [/etc
      ]
      [/home, fill=green!50, for children={fill=green!50}
        [Gwen
        ]
        [Dai
        ]
      ]
      [/mnt
      ]
      [/sbin, symlink
      ]
      [/usr
      ]
      [/var
      ]
    ]
  \end{forest}
\end{document}

forest directories

cfr
  • 198,882