在 Tikz 图片下方添加括​​号

在 Tikz 图片下方添加括​​号

我目前在 Tikz 中制作了以下时间线/图片: 在此处输入图片描述

对应下面的代码:

\begin{figure}
\caption{Scaling approach}
   \noindent\begin{tikzpicture}
    \matrix (M) [
        matrix of nodes,
        nodes={
           minimum height = 7mm,
           minimum width = 1.4cm,
           outer sep=0,
           anchor=center,
           draw,fill=white!20 % <-added
        },
        column 1/.style={
            nodes={draw=none,fill=none}, % <-- added fill=none
            minimum width = 4cm
        },
        row sep=5mm, column sep=-\pgflinewidth,
        nodes in empty cells,
        e/.style={fill=black!90}, % Cells with E will be blacc?
        w/.style={fill=white!90}, % Cells with E will be blacc?
         g/.style={fill=black!20} % Cells with E will be blacc?
      ]
      {
   \hspace{1.32cm} & & & & &   & |[g]| & |[g]|& |[e]| & |[e]| \\
      };
      \draw (M-1-7.north west) ++(0,2mm) coordinate (LT) edge[|<->|, >= latex] node[above]{Validation} (LT-|M-1-8.north east); % changed 5 to 7
       \draw (M-1-2.north west) ++(0,2mm) coordinate (LT) edge[|<->|, >= latex] node[above]{Train} (LT-|M-1-6.north east);
       \draw (M-1-9.north west) ++(0,2mm) coordinate (LT) edge[|<->|, >= latex] node[above]{Out-of-sample} (LT-|M-1-10.north east); %
        \draw (M-2-2.north west) ++(0,03mm) coordinate (LT) edge[|<->|, >= latex] node[above]{In-sample interval} (LT-|M-1-8.north east); % changed 5 to 7
      % fold labels and arrows


       \foreach [
             count=\row,
             evaluate={\col=ifthenelse(\row==4, % if fourth row
                                       int(\row+6), % use seventh column
                                       int(\row+3)) % else use column row+1
                       }
                ] \txt in {k}
         {
            \draw [black!30,line width=1mm,-Triangle] (M-\row-10.east) ++(2mm,0) -- ++(7mm,0) node[black, right] {$E$}; 
          }
  \end{tikzpicture}
 \label{fig:fixed}
 \end{figure}

我想添加一个花括号和一些文字以下训练部分,以及验证部分下方的花括号和一些文本。有人知道如何实现吗?

答案1

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix,arrows.meta,decorations.pathreplacing}
\begin{document}
\begin{figure}
\caption{Scaling approach}
   \noindent\begin{tikzpicture}
    \matrix (M) [
        matrix of nodes,
        nodes={
           minimum height = 7mm,
           minimum width = 1.4cm,
           outer sep=0,
           anchor=center,
           draw,fill=white!20 % <-added
        },
        column 1/.style={
            nodes={draw=none,fill=none}, % <-- added fill=none
            minimum width = 4cm
        },
        row sep=5mm, column sep=-\pgflinewidth,
        nodes in empty cells,
        e/.style={fill=black!90}, % Cells with E will be blacc?
        w/.style={fill=white!90}, % Cells with E will be blacc?
         g/.style={fill=black!20} % Cells with E will be blacc?
      ]
      {
   \hspace{1.32cm} & & & & &   & |[g]| & |[g]|& |[e]| & |[e]| \\
      };
      \draw (M-1-7.north west) ++(0,2mm) coordinate (LT) edge[|<->|, >= latex] node[above]{Validation} (LT-|M-1-8.north east); % changed 5 to 7
       \draw (M-1-2.north west) ++(0,2mm) coordinate (LT) edge[|<->|, >= latex] node[above]{Train} (LT-|M-1-6.north east);
       \draw (M-1-9.north west) ++(0,2mm) coordinate (LT) edge[|<->|, >= latex] node[above]{Out-of-sample} (LT-|M-1-10.north east); %
        %\draw (M-2-2.north west) ++(0,03mm) coordinate (LT) edge[|<->|, >= latex] node[above]{In-sample interval} (LT-|M-1-8.north east); % changed 5 to 7
      % fold labels and arrows


       \foreach [
             count=\row,
             evaluate={\col=ifthenelse(\row==4, % if fourth row
                                       int(\row+6), % use seventh column
                                       int(\row+3)) % else use column row+1
                       }
                ] \txt in {k}
         {
            \draw [black!30,line width=1mm,-Triangle] (M-\row-10.east) ++(2mm,0) -- ++(7mm,0) node[black, right] {$E$}; 
          }
   \draw[decorate,decoration={brace,mirror,raise=0.5ex}] (M-1-2.south west) -- (M-1-6.south east) 
   node[midway,below=1ex]{something} ;
   \draw[decorate,decoration={brace,mirror,raise=0.5ex}] (M-1-7.south west) --
   (M-1-8.south east)  node[midway,below=1ex]{duck} ;
  \end{tikzpicture}
 \label{fig:fixed}
 \end{figure}
\end{document}

在此处输入图片描述

请注意,我必须进行评论%\draw (M-2-2.north west) ...,因为您的矩阵只有一行。

相关内容