我怎样才能在图表上添加大量乳胶?

我怎样才能在图表上添加大量乳胶?

我怎样才能轻松生成下面的图像?

我对给定图节点的缩放括号特别感兴趣。

这在 graphviz 中很容易做到,然后以某种方式将乳胶放在它上面,还是这个图像完全是手绘的?

当下图位于 pdf 中时,它在节点上和括号周围确实有可选择的文本。

Graphviz 生成带有括号和乳胶的图形树图像

答案1

使用 TikZ matrix

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,decorations.pathreplacing,matrix,positioning}
\colorlet{lightblue}{blue!60!white}
\colorlet{darkgreen}{green!60!black}
\begin{document}
\begin{tikzpicture}[
  >={Triangle[]},
  font=\ttfamily,
  b/.style = {lightblue,fill=lightblue!40},
  g/.style = {darkgreen,fill=darkgreen!40}
  ]
  \matrix[
  matrix of nodes,column sep=.5cm,row sep=.1cm,
  nodes={
    lightgray,draw,thick,fill=lightgray!40,circle,
    minimum size=3ex,inner sep=1pt,anchor=south
  }] (m) {
          &       &       &       &     {}&     {}\\
          &       &       &       &     {}&     {}\\
          &     {}&     {}&|[g]|{}&|[g]|{}&|[g]|E \\
          &       &       &       &     {}&     {}\\
   |[b]|S &|[b]|{}&|[b]|R &|[b]|{}&|[b]|{}&|[b]|E \\
          &       &       &       &     {}&     {}\\
          &     {}&     {}&|[g]|{}&|[g]|E &       \\
          &       &       &       &     {}&       \\
          &       &       &       &     {}&       \\
  };
  % Black arrows
  \foreach \i [remember=\i as \lasti (initially 4)] in {5,6}
    \draw[->] (m-3-\lasti.east) to (m-3-\i.west);
  \foreach \i [remember=\i as \lasti (initially 1)] in {2,...,6}
    \draw[->] (m-5-\lasti.east) to (m-5-\i.west);
  \draw[->] (m-7-4.east) to (m-7-5.west);
  % Green arrows
  \draw[darkgreen,->] (m-5-3.east) to[bend left] (m-3-4.west);
  \draw[darkgreen,->] (m-5-3.east) to[bend right] (m-7-4.west);
  % Gray arrows
  \foreach \i[evaluate=\i as \j using int(\i+1)] in {1,2} {
    \foreach \row/\bend in {3/left, 7/right}
      \draw[lightgray,->] (m-5-\i.east) to[bend \bend]  (m-\row-\j.west);
  }
  \foreach \i[evaluate=\i as \j using int(\i+1)] in {4,5} {
    \foreach \row/\bend in {1/left, 2/left}
      \draw[lightgray,->] (m-3-\i.east) to[bend \bend]  (m-\row-\j.west);
  }
  \foreach \i[evaluate=\i as \j using int(\i+1)] in {4,5} {
    \foreach \row/\bend in {4/left, 6/right}
      \draw[lightgray,->] (m-5-\i.east) to[bend \bend]  (m-\row-\j.west);
  }
  \foreach \row/\bend in {8/right, 9/right}
    \draw[lightgray,->] (m-7-4.east) to[bend \bend]  (m-\row-5.west);
  % Loss
  \node[right=0pt of m-3-6] {loss=0};
  \node[right=0pt of m-5-6] {loss=.2};
  \node[right=0pt of m-7-5] {loss=.8};
  % Braces
  \draw[decorate,decoration={brace,amplitude=10pt},lightblue,thick]
    (m-7-3 |- m-7-3.south) -- node[below=10pt] (rollin) {rollin} (m-5-1 |- m-7-3.south);
  \draw[decorate,decoration={brace,amplitude=10pt},lightblue,thick]
    (m-5-6 |- m-9-5.south) -- node[below=10pt] (rollout) {rollout} (m-5-4 |- m-9-5.south);
  \path (rollin) -- node[lightblue,align=right,rotate=90] {one-step \\ deviations} (rollout);
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容