减少森林目录树的垂直空间

减少森林目录树的垂直空间

我正在努力使用森林类减少目录树的垂直空间。 我的代码基于这个 SO-Answer (https://tex.stackexchange.com/a/328890/32924)。尽管我添加了inner ysep=0pt树的样式和文件的样式,但生成的树间距不均匀(见图)。

此外,我想问您是否知道如何删除目录树的根元素(即系统)并将配置、库和文件显示为目录的根元素。

在此处输入图片描述

我使用的代码是:

\begin{document}
 \begin{forest}
      for tree={
        font=\ttfamily,
        grow'=0,
        child anchor=west,
        parent anchor=south,
        anchor=west,
        calign=first,
        inner xsep=7pt,
        inner ysep=0pt,
        edge path={
          \noexpand\path [draw, \forestoption{edge}]
          (!u.south west) +(7.5pt,0) |- (.child anchor) pic {folder} \forestoption{edge label};
        },
        % style for your file node 
        file/.style={edge path={\noexpand\path [draw, \forestoption{edge}]
          (!u.south west) +(7.5pt,0) |- (.child anchor) \forestoption{edge label};},
          inner xsep=2pt,inner ysep=0pt,font=\small\ttfamily
                     },
        before typesetting nodes={
          if n=1
            {insert before={[,phantom]}}
            {}
        },
        fit=band,
        before computing xy={l=15pt},
      }  
    [/
      [config
      ]
      [lib
        [Access
        ]
        [file.txt,file
        ]
      ]
      [file2.txt,file
      ]
      [gzipfile.txt,file
      ]
      [gzipfile2.txt,file
      ]
    ]
 \end{forest}
 \end{document}

答案1

要减小垂直间距,您需要更改s sep,因为文件夹格式的同级元素是垂直排列的。下图有s sep=2pt,但您可以将其缩小(甚至可以为负数,但这会重叠)。要保持间距均匀,您需要单元格的高度一致,因此我设置了minimum height=3mm。无需更改inner y sep

在此处输入图片描述

我不确定没有系统节点时您想要的最终外观是什么样的。我删除了它,但我认为这不是您想要的。也许可以提出一个新问题,并附上您想要的输出的草图。

\documentclass{article}

\usepackage{forest}

\definecolor{folderbg}{RGB}{124,166,198}
\definecolor{folderborder}{RGB}{110,144,169}

\def\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);
      }
    }

\begin{document}
 \begin{forest}
      for tree={
        font=\ttfamily,
        grow'=0,
        child anchor=west,
        parent anchor=south,
        anchor=west,
        calign=first,
        inner xsep=7pt,
        %inner ysep=0pt,
        s sep=2pt,
        minimum height=3mm,
        edge path={
          \noexpand\path [draw, \forestoption{edge}]
          (!u.south west) +(7.5pt,0) |- (.child anchor) pic {folder} \forestoption{edge label};
        },
        % style for your file node 
        file/.style={edge path={\noexpand\path [draw, \forestoption{edge}]
          (!u.south west) +(7.5pt,0) |- (.child anchor) \forestoption{edge label};},
          inner xsep=2pt,inner ysep=0pt,font=\small\ttfamily
                     },
        before typesetting nodes={
          if n=1
            {insert before={[,phantom]}}
            {}
        },
        fit=band,
        before computing xy={l=15pt},
      }  
    [
      [config
      ]
      [lib
        [Access
        ]
        [file.txt,file
        ]
      ]
      [file2.txt,file
      ]
      [gzipfile.txt,file
      ]
      [gzipfile2.txt,file
      ]
    ]
 \end{forest}
 \end{document}

相关内容