改变森林节点的颜色

改变森林节点的颜色

我正在尝试使用 Overleaf 将 LaTeX 森林图中某些块的颜色更改为绿色,将某些块的颜色更改为红色。但我没有取得任何进展。我当前的代码是:

\usepackage{tikz}
\usetikzlibrary{trees,positioning,shapes,shadows,arrows}
\usepackage{forest}
\usetikzlibrary{shadows}
\usetikzlibrary{arrows.meta,shadows.blur}
\tikzset{every shadow/.style={shadow xshift=5pt,shadow yshift=-5pt}}
\begin{figure}
\begin{forest}
  forked edges,
  for tree={font=\sffamily, rounded corners, top color=gray!5, bottom color=gray!10, edge+={darkgray, line width=1pt}, draw=darkgray, align=center, anchor=children},
  before packing={where n children=3{calign child=2, calign=child edge}{}},
  before typesetting nodes={where content={}{coordinate}{}},
  where level<=1{line width=2pt}{line width=1pt},
  [\textbf{220 TLD glow curves}\\, blur shadow
    [\textbf{Cluster 0}\\185

    [\textbf{Cluster 0.0}\\158]
        [
          [\textbf{Cluster 0.2}\\5]
          [
            [\textbf{Outlier 0.4}\\6]
          ]
          [\textbf{Outlier 0.3}\\8]
        ]
        [\textbf{Cluster 0.1}\\8]
      ]
    
    [\textbf{Cluster 1}\\10]
    [\textbf{Cluster 2}\\3]
          [\textbf{Cluster 3}\\5]
            [\textbf{Cluster 4}\\5]
          [\textbf{Outlier -1}\\12]
       
      ]

\end{forest}
\caption{\label{tab:table-1}Tree graph representing final classification of all TLD glow curves.}
\end{figure}

返回:

在此处输入图片描述

我想将块 Cluster 0.0、0.1 和 0.2 更改为绿色,并将其余块更改为红色(除了 220 TL 发光曲线和 Cluster 0,保留为灰色)。

答案1

  • 您的代码片段包含许多错误。例如:罚款树代码中有空行,未定义
  • 在显示问题代码之前请务必检查代码

更改某些关节节点颜色的最简单方法是向该节点添加颜色选项。例如

[\textbf{Cluster 1}\\10, draw=green, top color=green!5, bottom color=green!30]

更正您的代码片段并完成为小文档 MWE (最小工作示例) 的一个例子是:

\documentclass[12pt, margin=3mm]{standalone}
\usepackage[edges]{forest}

\usetikzlibrary{arrows.meta, 
                shadows, shadows.blur}

\tikzset{every shadow/.style={shadow xshift=5pt,shadow yshift=-5pt}}
\begin{document}
    \begin{forest}
forked edges,
for tree = {
    rounded corners, 
    top color=gray!5, bottom color=gray!30, 
    edge+={darkgray, line width=1pt}, 
    draw=darkgray, 
    align=center, 
    anchor=children,
    l sep=7mm,
    fork sep = 4mm
            },
before packing = {where n children=3{calign child=2, calign=child edge}{}},
before typesetting nodes={where content={}{coordinate}{}},
where level<=1{line width=2pt}{line width=1pt},
[\textbf{220 TLD glow curves}\\, blur shadow
    [\textbf{Cluster 0}\\185
        [\textbf{Cluster 0.0}\\158]
            [
                [\textbf{Cluster 0.2}\\5]
                    [
                        [\textbf{Outlier 0.4}\\6]
                    ]
                [\textbf{Outlier 0.3}\\8]
            ]
        [\textbf{Cluster 0.1}\\8]
    ]
    [\textbf{Cluster 1}\\10, draw=green, top color=green!5, bottom color=green!30]
    [\textbf{Cluster 2}\\3, draw=red, top color=red!5, bottom color=red!30,]
          [\textbf{Cluster 3}\\5]
            [\textbf{Cluster 4}\\5]
          [\textbf{Outlier -1}\\12]
      ]
\end{forest}
\end{document}

在此处输入图片描述

这就是你所追求的吗?

相关内容