在 Tikz 中使用文件夹和文件创建目录树

在 Tikz 中使用文件夹和文件创建目录树

我从@Gonzalo 那里借了代码回答。我想制作包含文件夹和文件的目录树,如下图所示。

在此处输入图片描述

MWE 如下:

\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=10pt]}}
        {}
    },
    fit=band,
    s sep=12pt,
    before computing xy={l=25pt},
  }
[{\myfolder[fgreen]{UAFSynopsis}}
  [{\myfolder{Documentation}}]
  [{\myfolder{SynopsisMain}}
    [01Abstract.tex]
    [02Signature.tex]
    [03Introduction.tex]
    [04LiteratureReview.tex]
    [05MaterialMethod.tex]
    [06BackSignature.tex]
    [SynopsisBib.bib]
  ]
 [LICENSE]
 [NEWS.md]
 [README.html]
 [README.md]
 [Makefile]
 [MPhilSynopsis.tex]
 [MPhilSynopsis.pdf]
 [UAFSynopsis.cls]
]
\end{forest}

\end{document}

问题

  1. 如何从文件夹名称中删除 / 并正确对齐它们。
  2. 减少两个文件名之间的垂直间距

任何帮助都将不胜感激。谢谢

答案1

这是更新的版本。

\documentclass[tikz,border=10pt,multi,dvipsnames,svgnames,x11names]{standalone}
\usepackage[edges]{forest}
\usetikzlibrary{backgrounds}
\begin{document}
% addaswyd o gôd Gonzalo Medina: http://tex.stackexchange.com/a/270761/
\definecolor{fblue}{RGB}{92,144,192}
\definecolor{fgreen}{RGB}{34,162,70}

\forestset{% addaswyd o gôd Gonzalo Medina: http://tex.stackexchange.com/a/270761/
  declare toks={my folder colour}{fblue},
  my folder/.style={
    inner xsep=10pt,
    inner ysep=8pt,
    tikz+={
      \begin{scope}[on background layer]
        \filldraw[rounded corners=1pt, fill=\forestoption{my folder colour}, draw=white, double=black]
        ([xshift=-10pt,yshift=-5pt].north east) -- ++(-4pt,10pt) -- ++(-10pt,0) -- ++(-4pt,-10pt) -- cycle;
        \filldraw[rounded corners, draw=white, double=black, top color=\forestoption{my folder colour}, bottom color=\forestoption{my folder colour}!30]
        ([xshift=-4pt].north east) -- ([xshift=-10pt].south east) -- ([xshift=10pt].south west) -- ([xshift=4pt].north west) -- cycle;
      \end{scope}
    },
  },
}

\begin{forest}
  for tree={% addaswyd o gôd Gonzalo Medina: http://tex.stackexchange.com/a/270761/
    folder,
    font=\sffamily,
    grow'=0,
    edge+={rounded corners},
  }
  [{UAFSynopsis}, my folder=fgreen
     [{Documentation}, my folder]
     [SynopsisMain, my folder
        [01Abstract.tex]
        [02Signature.tex]
        [03Introduction.tex]
        [04LiteratureReview.tex]
        [05MaterialMethod.tex]
        [06BackSignature.tex]
        [SynopsisBib.bib]
     ]
     [LICENSE]
     [NEWS.md]
     [README.html]
     [README.md]
     [Makefile]
     [MPhilSynopsis.tex]
     [MPhilSynopsis.pdf]
     [UAFSynopsis.cls]
  ]
\end{forest}
\end{document}

更新文件夹

相关内容