答案1
您需要一个matrix
节点和两个fit
节点。
\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{positioning, matrix, fit}
\begin{document}
\begin{tikzpicture}
\matrix (A) [matrix of nodes]
{1 & 2 & 3 & 4 & 5\\
1 & 1 & 2 & 1 & 2\\
1 & 2 & 3 & 4 & 5\\
1 & 1 & 2 & 1 & 2\\
1 & 2 & 3 & 4 & 5\\
1 & 1 & 2 & 1 & 2\\
1 & 2 & 3 & 4 & 5\\
1 & 1 & 2 & 1 & 2\\
1 & 2 & 3 & 4 & 5\\
};
\node[draw=blue, thick, inner sep=2pt, fit=(A-6-3.north west) (A-9-5.south east)] (BB) {};
\node[draw=red, thick, inner sep=2pt, fit=(A-4-2.north west) (BB.south east)] (BA) {};
\node[red, right= 0mm of BA.north east] (LA) {Box A};
\node[blue] at (BB-|LA) {Box B};
\end{tikzpicture}
\end{document}