tikz 中垂直森林图中独特的级别颜色

tikz 中垂直森林图中独特的级别颜色

在此处输入图片描述

\documentclass[tikz,border=5pt,multi]{standalone}

    \usepackage{forest,array}

    \usetikzlibrary{shadows}

    \begin{document}

    \newcolumntype{C}[1]{>{\centering}p{#1}}

    \begin{forest}
    for tree={
      if level=0{align=center}{% allow multi-line text and set alignment
        align={@{}C{45mm}@{}},
      },
      grow=east,
      draw,
      font=\sffamily\bfseries,
      edge path={
        \noexpand\path [draw, \forestoption{edge}] (!u.parent anchor) -- +(5mm,0) |- (.child anchor)\forestoption{edge label};
      },
      parent anchor=east,
      child anchor=west,
      l sep=10mm,
      tier/.wrap pgfmath arg={tier #1}{level()},
      edge={ultra thick, rounded corners=2pt},
      fill=white,
      rounded corners=2pt,
      drop shadow,
    }
    [UML Diagram
      [Structure Diagram
        [Class Diagram]
        [Object Diagram]
        [Package Diagram]
        [Component Diagram]
        [Composite Structure Diagram]
        [Deployment Diagram]
        [Profile Diagram]
      ]
      [Behaviour Diagram
        [Use Case Diagram]
        [Activity Diagram]
        [State Machine Diagram]
        [Interaction Diagram
            [Sequence Diagram]
            [Communication Diagram]
            [Interaction Overview Diagram]
            [Timing Diagram]
        ]
      ]
    ]
    \end{forest}

    \end{document}

如何为父级(级别 1)和孙级(级别 2)分配唯一的颜色/填充。

致谢tikz 中的垂直森林图

谢谢

答案1

像这样?

在此处输入图片描述

为此你只需要添加到for tree={...}选项

      if level=1{fill=blue!30}{if level=3{fill=red!30}{}},

相关内容