使用森林改变框的颜色及其边缘

使用森林改变框的颜色及其边缘

我有一个根据以下代码制作的决策树。但是,到目前为止,我还没有能够摆脱方框的阴影属性。我希望名称周围的方框有黑色边缘和简单的白色背景。你能给我提示一下如何做到这一点吗?

祝好,朱利安


\begin{forest}
  for tree={
    edge={thick, draw=black},
    font=\sffamily\bfseries,
    text=black,
    top color=white!90!black,
    bottom color=white!60!black,
    text width=35mm,
    text centered,
    minimum height=10mm,
    rounded corners = 3,
    grow=right,right,
    l sep'=20mm,
    s sep'=10mm,
  },
  forked edges,
  [Food\\
    [Bread\\Oats]
    [Dairy goods\\
    [Cream]
    [Yoghurt]
    [Milk]
    [Butter]
    [Cheese]
    ]
    [Potatoes\\Pasta\\Rice]
    [Fruits]
    [Vegetables]
    [Meat\\
    [Poultry]
    [Pork]
    [Beef]
  ]]
\end{forest}


答案1

试试这个代码。定义的样式(block)处理框的属性。

A

\documentclass{article}
\usepackage[edges]{forest}

\tikzset{
    block/.style={draw, 
    anchor=east,    
    font=\sffamily\bfseries,
    fill=white, % <<<<<<<<<<<<<<<<
    text width=35mm, 
    text=black,
    text centered, 
    rounded corners=3pt,
    minimum height=10mm},   
}

\begin{document}
\begin{forest}
  for tree={
    edge={thick, draw=black},
    block, % style <<<<<<<<<<   
    grow=0,
    l sep+=10mm,
    s sep+=10mm,
},
forked edges,
    [Food\\
    [Bread\\Oats]
    [Dairy goods\\
    [Cream]
    [Yoghurt]
    [Milk]
    [Butter]
    [Cheese]
    ]
    [Potatoes\\Pasta\\Rice]
    [Fruits]
    [Vegetables]
    [Meat\\
    [Poultry]
    [Pork]
    [Beef]
    ]]
\end{forest}    
    
\end{document}

如果你计划创建多棵树,你可能需要定义一个默认样式,例如

\forestset{
    default preamble={
      for tree={
        edge={thick, draw=black},
        block, % style <<<<<<<<<<   
        grow=0,
        l sep+=10mm,
        s sep+=10mm,
    },
        forked edges,
        }}

相关内容