LaTeX 特征图(添加简单的图例)

LaTeX 特征图(添加简单的图例)

我应用了以下代码来绘制特征图。我想向图例添加替代符号(未填充的角度),如图所示。你能帮忙吗

\documentclass[border=10pt,tikz,multi]{standalone}
\usetikzlibrary{angles,shadows.blur,positioning,backgrounds}
\usepackage{forest}
\forestset{
  declare count register=disjuncts from,
  disjuncts from'=0,
  declare count register=concrete from,
  concrete from'=2,
  concrete colour/.code={\colorlet{concretecol}{#1}},
  abstract colour/.code={\colorlet{abstractcol}{#1}},
  draw colour/.code={\colorlet{drawcol}{#1}},
  concrete colour=gray,
  abstract colour=white,
  draw colour=black,
  /tikz/mandatory/.style={circle, fill=drawcol, draw=drawcol},
  /tikz/optional/.style={circle, draw=drawcol, fill=white},
  /tikz/concrete/.style={fill=concretecol, draw=drawcol},
  /tikz/abstract/.style={fill=abstractcol, draw=drawcol},
  /tikz/or/.style={},
  mandatory/.style={edge label={node [mandatory] {}}},
  optional/.style={edge label={node [optional] {}}},
  or/.style={for first={disjunct}},
  disjunct/.style={
    tikz+={\path (.parent) coordinate (A) -- (!u.children) coordinate (B) -- (!ul.parent) coordinate (C) pic [fill=drawcol] {angle};}
  },
  disjunction tree/.style={
    where={isodd(n_children())}{
      for n={int((n_children()+1)/2)}{calign with current},
    }{
      calign=midpoint,
    },
    before typesetting nodes={
      for nodewalk={
        filter/.wrap pgfmath arg={{level>=##1}{n_children()>1}}{(disjuncts_from)}
      }{
        or,
      },
      where={level()>=(concrete_from)}{
        concrete,
      }{
        abstract,
      },
      tikz+={
        [font=\sffamily]
        \node (l) [anchor=north west, xshift=10pt] at (current bounding box.north east) {Legend};
        \foreach \i/\j [remember=\i as \k (initially l)] in {mandatory/Mandatory,optional/Optional,or/Or,abstract/Abstract,concrete/Concrete}
        {
          \node (\i) [below=20pt of \k.north, anchor=north, text centered, \i, minimum width=5pt,] {};
          \node (\j) [right=15pt of \i.center -| mandatory.west, anchor=west] {\j};
        };
        \draw [drawcol] (or.south west) coordinate (A) -- (or.north) coordinate (B) -- (or.south east) coordinate (C) pic [fill=drawcol, angle radius=5pt] {angle};
        \foreach \i in {mandatory,optional} \draw [darkgray] (\i.north east) -- +(45:5pt);
        \node (c) [below=0pt of Concrete.south] {};
        \scoped[on background layer]{\node [draw, fill=white, blur shadow, fit=(l) (Mandatory) (Optional) (Or) (Abstract) (Concrete) (c), rounded corners] {};}
      },
    },
    for tree={
      parent anchor=children,
      child anchor=parent,
      l'+=10mm,
      blur shadow,
      rounded corners,
      text height=2ex,
      text depth=.5ex,
      font=\sffamily,
    },
  },
}
\begin{document}
\begin{forest}% addaswyd o gôd Salim Bou: https://tex.stackexchange.com/a/335782/
  disjunction tree,
  disjuncts from'=1,
  concrete from'=1,
  concrete colour=blue!85!cyan!40,
  abstract colour=blue!85!cyan!15,
  draw colour=darkgray,
  [Emergency Response System
    [User interface, mandatory]
    [Inform emergency,  mandatory
      [Inform Earthquake, abstract colour=blue!85!cyan!15]
      [Inform flood]
    ]
    [Display neighbourhood, mandatory
      [Map
        [Display danger zone]
        [Display safe zone]
        [Display path to safe zone]
      ]
      [Textual direction]
    ]
    [Shortcut calls, optional
      [Cops]
      [Ambulance]
      [Fireman]
    ]
  ]
\end{forest}
\end{document}

在此处输入图片描述

答案1

我对森林一无所知,但我知道如何使用保存箱和 tikz。

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{angles,shadows.blur,positioning,backgrounds,arrows.meta}
\usepackage{forest}
\forestset{
  declare count register=disjuncts from,
  disjuncts from'=0,
  declare count register=concrete from,
  concrete from'=2,
  concrete colour/.code={\colorlet{concretecol}{#1}},
  abstract colour/.code={\colorlet{abstractcol}{#1}},
  draw colour/.code={\colorlet{drawcol}{#1}},
  concrete colour=gray,
  abstract colour=white,
  draw colour=black,
  /tikz/mandatory/.style={circle, fill=drawcol, draw=drawcol},
  /tikz/optional/.style={circle, draw=drawcol, fill=white},
  /tikz/concrete/.style={fill=concretecol, draw=drawcol},
  /tikz/abstract/.style={fill=abstractcol, draw=drawcol},
  /tikz/or/.style={},
  mandatory/.style={edge label={node [mandatory] {}}},
  optional/.style={edge label={node [optional] {}}},
  or/.style={for first={disjunct}},
  disjunct/.style={
    tikz+={\path (.parent) coordinate (A) -- (!u.children) coordinate (B) -- (!ul.parent) coordinate (C) pic [fill=drawcol] {angle};}
  },
  disjunction tree/.style={
    where={isodd(n_children())}{
      for n={int((n_children()+1)/2)}{calign with current},
    }{
      calign=midpoint,
    },
    before typesetting nodes={
      for nodewalk={
        filter/.wrap pgfmath arg={{level>=##1}{n_children()>1}}{(disjuncts_from)}
      }{
        or,
      },
      where={level()>=(concrete_from)}{
        concrete,
      }{
        abstract,
      },
%
    },
    for tree={
      parent anchor=children,
      child anchor=parent,
      l'+=10mm,
      blur shadow,
      rounded corners,
      text height=2ex,
      text depth=.5ex,
      font=\sffamily,
    },
  },
}
\begin{document}
\bgroup
\sbox0{%
\begin{forest}% addaswyd o gôd Salim Bou: https://tex.stackexchange.com/a/335782/
  disjunction tree,
  disjuncts from'=1,
  concrete from'=1,
  concrete colour=blue!85!cyan!40,
  abstract colour=blue!85!cyan!15,
  draw colour=darkgray,
  [Emergency Response System
    [User interface, mandatory]
    [Inform emergency,  mandatory
      [Inform Earthquake, abstract colour=blue!85!cyan!15]
      [Inform flood]
    ]
    [Display neighbourhood, mandatory
      [Map
        [Display danger zone]
        [Display safe zone]
        [Display path to safe zone]
      ]
      [Textual direction]
    ]
    [Shortcut calls, optional
      [Cops]
      [Ambulance]
      [Fireman]
    ]
  ]
\end{forest}}%
%
\sbox1{\begin{tabular}{clclcl}
\tikz{\draw (0,0) node[circle,fill=black,inner sep=.5ex] (A) {} (A.north) -- (0,2ex);} & Mandatory &
\tikz{\draw (0,0) coordinate(A) -- (2ex,2ex) coordinate(B) -- (4ex,0) coordinate(C)
  pic[draw, angle radius=1.5ex] {angle=A--B--C};} & Alternative &
\tikz{\draw[dashed,-latex] (0,0) (0,1ex) -- (2em,1ex);} & Requires \\
\tikz{\draw (0,0) node[circle,draw,inner sep=.5ex] (A) {} (A.north) -- (0,2ex);} & Optional &
\tikz{\draw (0,0) coordinate(A) -- (2ex,2ex) coordinate(B) -- (4ex,0) coordinate(C)
  pic[fill=black, angle radius=1.5ex] {angle=A--B--C};} & Or &
\tikz{\draw[dashed,latex-latex] (0,0) (0,1ex) -- (2em,1ex);} & Excludes \\
\end{tabular}}%
%
\begin{tikzpicture}
  \node (forest){\usebox0};
  \node[below=2ex,draw,rounded corners] at (forest.south) {\usebox1};
\end{tikzpicture}
\egroup
\end{document}

演示

相关内容