包森林:创建带有注释的目录结构

包森林:创建带有注释的目录结构

我想使用 forest 包创建一个带有注释的文件夹结构。我发现了非常好的目录结构,例如贡萨洛·梅迪纳用森林制作,但我不明白如何添加不同风格的评论,如下图所示:

带注释的目录结构

非常感谢你的帮助!

保罗

答案1

改编自cfr 的答案这大大改进了 Gonzalo 的代码,使用当前版本forest,您可以简单地制作一个宏来在文件夹/文件名上引入注释:

\documentclass[]{article}
\usepackage[edges]{forest}
\usepackage{array}
\definecolor{folderbg}{RGB}{124,166,198}
\definecolor{folderborder}{RGB}{110,144,169}
\newlength\Size
\setlength\Size{4pt}
\tikzset{%
  folder/.pic={%
    \filldraw [draw=folderborder, top color=folderbg!50, bottom color=folderbg] (-1.05*\Size,0.2\Size+5pt) rectangle ++(.75*\Size,-0.2\Size-5pt);
    \filldraw [draw=folderborder, top color=folderbg!50, bottom color=folderbg] (-1.15*\Size,-\Size) rectangle (1.15*\Size,\Size);
  },
  file/.pic={%
    \filldraw [draw=folderborder, top color=folderbg!5, bottom color=folderbg!10] (-\Size,.4*\Size+5pt) coordinate (a) |- (\Size,-1.2*\Size) coordinate (b) -- ++(0,1.6*\Size) coordinate (c) -- ++(-5pt,5pt) coordinate (d) -- cycle (d) |- (c) ;
  },
}
\forestset{%
  declare autowrapped toks={pic me}{},
  pic dir tree/.style={%
    for tree={%
      folder,
      font=\itshape,
      grow'=0,
    },
    before typesetting nodes={%
      for tree={%
        edge label+/.option={pic me},
      },
    },
  },
  pic me set/.code n args=2{%
    \forestset{%
      #1/.style={%
        inner xsep=2\Size,
        pic me={pic {#2}},
      }
    }
  },
  pic me set={directory}{folder},
  pic me set={file}{file},
}
\newcommand{\fname}[2]{\begin{tabular}{m{1cm}@{\quad}m{4cm}}#1 & \normalfont#2\end{tabular}}
\begin{document}

\begin{forest}
  pic dir tree,
  where level=0{}{% folder icons by default; override using file for file icons
    directory,
  },
  [system
    [\fname{config}{A comment about this folder}
    ]
    [lib
      [Access
      ]
      [Plugin
      ]
      [\fname{file.txt}{A comment about this file}, file
      ]
    ]
    [templates
    ]
    [tests
    ]
  ]
\end{forest}
\end{document}

代码输出

相关内容