Tikz 矩阵下方的子矩阵

Tikz 矩阵下方的子矩阵

我知道这里有一些非常有才华的 tikz 人!我正在寻找类似的东西:

在此处输入图片描述

这就是我所能想到的,如何在上矩阵的 4 列内正确对齐 5 列矩阵……?

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{matrix}

\begin{document}
  \begin{tikzpicture}
  \matrix (M) [matrix of nodes,
  nodes={minimum height = 7mm, minimum width = 1.2cm, outer sep=0, anchor=center, draw},
  column 1/.style={nodes={draw=none}, minimum width = 4cm},
  row sep=1mm, column sep=-\pgflinewidth, nodes in empty cells,
  e/.style={fill=green!10}, f/.style={fill=blue!10}
  ]
  {
    1: & |[e]| & & & & \\
    2: & & |[e]| & & & \\
    3: & & & |[e]| & & \\
    4: & & & & |[e]| & \\
    5: & & & & & |[e]| \\
  };

  \node [above of= M-1-2, node distance = 3.5em, rotate=90] () {Test1 }; 
  \node [above of= M-1-3, node distance = 3.5em, rotate=90] () {Test2}; 
  \node [above of= M-1-4, node distance = 3.5em, rotate=90] () {Test3}; 
  \node [above of= M-1-5, node distance = 3.5em, rotate=90] () {Test4}; 
  \node [above of= M-1-6, node distance = 3.5em, rotate=90] () {Test5}; 

  \draw (M-5-2.south west) coordinate (LT) edge[|<->|, >= latex] node[below, node distance = 4em]{Total number of datasets} (LT-|M-5-6.south east);
  \end{tikzpicture}
\end{document}

答案1

你已经完成了所有艰苦的工作。只需将一些维度乘以即可4/5=0.8得出

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{matrix,fit,decorations.pathreplacing}

\begin{document}
  \begin{tikzpicture}
  \matrix (M) [matrix of nodes,
  nodes={minimum height = 7mm, minimum width = 1.2cm, outer sep=0, anchor=center, draw},
  column 1/.style={nodes={draw=none}, minimum width = 4cm},
  row sep=1mm, column sep=-\pgflinewidth, nodes in empty cells,
  e/.style={fill=green!10}, f/.style={fill=blue!10}
  ]
  {
    1: & |[e]| & & & & \\
    2: & & |[e]| & & & \\
    3: & & & |[e]| & & \\
    4: & & & & |[e]| & \\
    5: & & & & & |[e]| \\
  };

  \node [above of= M-1-2, node distance = 3.5em, rotate=90] () {Test1 }; 
  \node [above of= M-1-3, node distance = 3.5em, rotate=90] () {Test2}; 
  \node [above of= M-1-4, node distance = 3.5em, rotate=90] () {Test3}; 
  \node [above of= M-1-5, node distance = 3.5em, rotate=90] () {Test4}; 
  \node [above of= M-1-6, node distance = 3.5em, rotate=90] () {Test5}; 

  \draw (M-5-2.south west) coordinate (LT) edge[|<->|, >= latex] node[below, node distance = 4em]{Total number of datasets} (LT-|M-5-6.south east);
  \node[fit=(M-5-2) (M-5-5),yshift=-0.6cm,inner sep=0pt](F){};
  \draw[thick,decorate,decoration=brace] (F.south east) -- (F.south west);
  \matrix (M') [anchor=north west,matrix of nodes,
  nodes={minimum height = 7mm, minimum width = 0.8*1.2cm, outer sep=0, anchor=center, draw},
  column 1/.style={nodes={draw=none},},
  row sep=1mm, column sep=-\pgflinewidth, nodes in empty cells,
  ] 
  at ([yshift=-1cm,xshift=0.2*1.2cm]M.south west)
  {1: & x& x & x & x & x\\ 
   2: & x& x & x & x & x\\ 
   3: & x& x & x & x & x\\ 
   4: & x& x & x & x & x\\ };
  \end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

一种可能性是进行hard-coded如下定位:

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{matrix, positioning}
\usetikzlibrary{patterns, decorations.pathreplacing}
\tikzstyle{overbrace style}=[decorate,decoration={mirror, brace,raise=0.5cm}]
\begin{document}
  \begin{tikzpicture}
  \matrix (M) [matrix of nodes,
  nodes={minimum height = 7mm, minimum width = 1.2cm, outer sep=0, anchor=center, draw},
  column 1/.style={nodes={draw=none}, minimum width = 4cm},
  row sep=1mm, column sep=-\pgflinewidth, nodes in empty cells,
  e/.style={fill=green!10}, f/.style={fill=blue!10}
  ]
  {
    1: & |[e]| & & & & \\
    2: & & |[e]| & & & \\
    3: & & & |[e]| & & \\
    4: & & & & |[e]| & \\
    5: & & & & & |[e]| \\
  };

  \node [above of= M-1-2, node distance = 3.5em, rotate=90] () {Test1 }; 
  \node [above of= M-1-3, node distance = 3.5em, rotate=90] () {Test2}; 
  \node [above of= M-1-4, node distance = 3.5em, rotate=90] () {Test3}; 
  \node [above of= M-1-5, node distance = 3.5em, rotate=90] () {Test4}; 
  \node [above of= M-1-6, node distance = 3.5em, rotate=90] () {Test5}; 
    \node[below = 0 cm of M-5-4.south west] (A) {};
  \draw (M-5-2.south west) coordinate (LT) edge[|<->|, >= latex] node[below, node distance = 4em]{Total number of datasets} (LT-|M-5-6.south east);
 \draw [overbrace style] (M-5-2.south west) -- (LT-|M-5-6.south east);
 \node[below = 0.5 cm of A] (B) {};
 \matrix (M2) [below = 0cm of B,matrix of nodes,
 nodes={minimum height = 7mm, minimum width = 1.2cm, outer sep=0, anchor=center, draw},
 column 1/.style={nodes={draw=none}, minimum width = 4cm},
 row sep=1mm, column sep=-\pgflinewidth, nodes in empty cells,
 e/.style={fill=green!10}, f/.style={fill=blue!10}
 ]
 {
    1: & |[e]| & & & & \\
    2: & & |[e]| & & & \\
    3: & & & |[e]| & & \\
    4: & & & & |[e]| & \\
    5: & & & & & |[e]| \\
 };

 \node [above of= M-1-2, node distance = 3.5em, rotate=90] () {Test1 }; 
 \node [above of= M-1-3, node distance = 3.5em, rotate=90] () {Test2}; 
 \node [above of= M-1-4, node distance = 3.5em, rotate=90] () {Test3}; 
 \node [above of= M-1-5, node distance = 3.5em, rotate=90] () {Test4}; 
 \node [above of= M-1-6, node distance = 3.5em, rotate=90] () {Test5}; 

 \draw (M-5-2.south west) coordinate (LT) edge[|<->|, >= latex] node[below, node distance = 4em]{Total number of datasets} (LT-|M-5-6.south east);
  \end{tikzpicture}
\end{document}

这将导致:

在此处输入图片描述

相关内容