使用文件夹图标绘制目录树

使用文件夹图标绘制目录树

我需要创建一个类似下面的图形 图像

图像使用文件夹图标显示目录树。您建议我做什么?

答案1

这是一种使用的可能性forestTikZ

在此处输入图片描述

代码:

\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}

该命令\myfolder有一个用于文件夹标签的强制参数和一个用于颜色的可选参数。

答案2

这是一个forest解决方案:

\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}

森林目录

相关内容