重新格式化目录树样式

重新格式化目录树样式

我有一个目录树,几乎看起来像这样:

样本目录树

上面的图片是我想要实现的。这是我在帮助下稍作修改后得到的制作(简单)目录树

我的目录树

我知道我应该再努力一点,但在制作图表方面,尤其是与复杂树相关的图表方面,我并不是专业人士。在这里,我正在寻找一种方法来使除主节点(或根节点)之外的每个节点的背景颜色变为灰色。主节点应该如图所示具有框。另外,我在寻找一种方法来任意修改节点,使其具有像主节点一样的框,如图中间和底部所示。另外,左边的小框应该有一个减号(展开形式)。顶部的标题是可选的,图像末尾的行将被忽略。只要方便,使用哪些包并不重要。

更新

fill我设法通过使用、inner seps sep以及编辑节点来模拟扩展形式来稍微改进我的图片edge path。现在我需要一点帮助来使边缘路径类似于第一幅图像。

我的图片2

这是我的代码:

\documentclass[border=5pt]{standalone}
\usepackage{forest}
\usepackage{xcolor}

\definecolor{mygray}{RGB}{224,224,224}
\begin{document}

\begin{forest}
  for tree={
    font=\sffamily,
     if level=0
      {fill=white,draw=black}
      {fill=mygray,draw=black},
    grow'=0,
    child anchor=west,
    parent anchor=south,
    anchor=west,
    calign=first,
    inner xsep= 15pt,
    s sep=15pt,
    edge path={
      \noexpand\path [draw, \forestoption{edge}]
      (!u.south west) +(7.5pt,0) |- node[fill=white,draw,inner sep=1pt,align=center] {$-$} (.child anchor)\forestoption{edge label};
    },
    before typesetting nodes={
      if n=1
        {insert before={[,phantom]}}
        {}
    },
    fit=band,
    before computing xy={l=35pt},
  }
[R1SC4000R - Processor for Service
  [SETUIXNAM]
  [{QC2UTIL1,R1SC3000ER,DOCERROR}]
  [STEPCONDITION
    [LOKUPUIX
        [R1SB8000R - Handle User Index\quad UIX,fill=white]
    ]
    [{GETFROMUIX,GETFROMUIX}]
    [{GETFROMUIX,GETFROMUIX}]
  ]
  [ONESUB
    [{QC2UTIL1,R1SC3000ER,DOCERROR}]
    [UIXPERM2TEMP
     [{GETFROMUIX,GETFROMUIX}]
     [CLRUIX
        [R1SB8000R - Handle User Index\quad UIX,fill=white]
     ]
    ]
  ]
]
\end{forest}

\end{document

答案1

如果我理解正确的话,这里有两个问题。首先,-只有当子文件夹有子项时,节点才应出现。其次,其他子项的边不应绘制在节点上-

对于第一个问题,我们可以使用if n children条件。如果没有子节点,我们就设置一条简单的边路径,不带节点;否则,设置一个带边框的边路径-

第二个问题可以通过改变绘制边缘的顺序来解决;必须从最后一个子节点开始绘制子节点的边缘。这可以通过设置draw tree edges processing ordernodewalk 样式(参见手册第 3.4.3 节)到tree reversed(第 3.8.3 节)来解决。

以下是完整的更新代码:

\documentclass[border=5pt]{standalone}
\usepackage{forest}
\usepackage{xcolor}

\definecolor{mygray}{RGB}{224,224,224}
\begin{document}

\begin{forest}
  draw tree edges processing order/.nodewalk style=tree reversed,
  for tree={
    font=\sffamily,
     if level=0
      {fill=white,draw=black}
      {fill=mygray,draw=black},
    grow'=0,
    child anchor=west,
    parent anchor=south,
    anchor=west,
    calign=first,
    inner xsep= 15pt,
    s sep=15pt,
    if n children=0{
      edge path={
        \noexpand\path [draw, \forestoption{edge}]
        (!u.south west) +(7.5pt,0) |- (.child anchor)\forestoption{edge label};
      },
    }{
      edge path={
        \noexpand\path [draw, \forestoption{edge}]
        (!u.south west) +(7.5pt,0) |- node[fill=white,draw,inner sep=1pt,align=center] {$-$} (.child anchor)\forestoption{edge label};
      },
    },
    before typesetting nodes={
      if n=1
        {insert before={[,phantom]}}
        {}
    },
    fit=band,
    before computing xy={l=35pt},
  }
[R1SC4000R - Processor for Service
  [SETUIXNAM]
  [{QC2UTIL1,R1SC3000ER,DOCERROR}]
  [STEPCONDITION
    [LOKUPUIX
        [R1SB8000R - Handle User Index\quad UIX,fill=white]
    ]
    [{GETFROMUIX,GETFROMUIX}]
    [{GETFROMUIX,GETFROMUIX}]
  ]
  [ONESUB
    [{QC2UTIL1,R1SC3000ER,DOCERROR}]
    [UIXPERM2TEMP
     [{GETFROMUIX,GETFROMUIX}]
     [CLRUIX
        [R1SB8000R - Handle User Index\quad UIX,fill=white]
     ]
    ]
  ]
]
\end{forest}

\end{document}

在此处输入图片描述

-更新:在根的左边也画出来

我认为,最好手动执行此操作:将根稍微向右移动一点,然后将放在-它的左边。问题在于根的子节点连接到根节点;解决方案:概括边缘路径分配以支持任意移位,并将其分别应用于根的子节点。

\documentclass[border=5pt]{standalone}
\usepackage{forest}
\usepackage{xcolor}

\definecolor{mygray}{RGB}{224,224,224}
\begin{document}

\begin{forest}
  draw tree edges processing order/.nodewalk style=tree reversed,
  my edge path/.style={
    edge path={
      \noexpand\path [draw, \forestoption{edge}]
      (!u.south west) #1 |- (.child anchor)\forestoption{edge label};
    },
  },
  my edge path with node/.style={
    edge path={
      \noexpand\path [draw, \forestoption{edge}]
      (!u.south west) #1 |- node[fill=white,draw,inner sep=1pt,align=center] {$-$} (.child anchor)\forestoption{edge label};
    },
  },
  for tree={
    font=\sffamily,
     if level=0
      {fill=white,draw=black}
      {fill=mygray,draw=black},
    grow'=0,
    child anchor=west,
    parent anchor=south,
    anchor=west,
    calign=first,
    inner xsep= 15pt,
    s sep=15pt,
    if n children=0{
      my edge path={+(7.5pt,0)},
    }{
      my edge path with node={+(7.5pt,0)},
    },
    before typesetting nodes={
      if n=1
        {insert before={[,phantom]}}
        {}
    },
    fit=band,
    before computing xy={l=35pt},
  },
  % The root will be shifted to the right, so the children need to connect to a
  % point a bit more to the left of it.
  for children={
    if n children=0{
      % We need 2.5pt (determined by visual inspection) to compensate for the
      % height difference between the root and its `-` box.
      my edge path with node={+(-15pt,+2.5pt)}
    }{
      my edge path={+(-15pt,+2.5pt)}
    }
  },
  % Shift the root to the right.
  before drawing tree={
    x+=7.5pt+15pt,
  },
  % Draw the `-` node on the left side of the root.
  tikz+={
    \node (root-) at ([xshift=-15pt].west) [fill=white,draw,inner sep=1pt] {$-$};
    \draw (root-) -- (!r.west);
  },
  [R1SC4000R - Processor for Service
    [SETUIXNAM]
    [{QC2UTIL1,R1SC3000ER,DOCERROR}]
    [STEPCONDITION
      [LOKUPUIX
        [R1SB8000R - Handle User Index\quad UIX,fill=white]
      ]
      [{GETFROMUIX,GETFROMUIX}]
      [{GETFROMUIX,GETFROMUIX}]
    ]
    [ONESUB
      [{QC2UTIL1,R1SC3000ER,DOCERROR}]
      [UIXPERM2TEMP
        [{GETFROMUIX,GETFROMUIX}]
        [CLRUIX
          [R1SB8000R - Handle User Index\quad UIX,fill=white]
        ]
      ]
    ]
  ]
\end{forest}

\end{document}

更新后的结果

相关内容