我想要生成如下图所示的矩阵:
目前,我有这样的代码:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
\matrix[matrix of math nodes,left delimiter = (,right delimiter = ),row sep=10pt,column sep = 10pt] (m) {
cpf_{11} & cpf_{12} & cpf_{13} & cpf_{14} \\
cpf_{21} & cpf_{22} & cpf_{23} & cpf_{24} \\
cpf_{31} & cpf_{32} & cpf_{33} & cpf_{34} \\
cpf_{41} & cpf_{42} & cpf_{43} & cpf_{44} \\};
\draw (m-1-1.north west) -- (m-2-1.south west) -- (m-2-2.south east) -- (m-1-2.north east) -- cycle;
\draw (m-1-3.north west) -- (m-2-3.south west) -- (m-2-4.south east) -- (m-1-4.north east) -- cycle;
\draw (m-3-1.north west) -- (m-4-1.south west) -- (m-4-2.south east) -- (m-3-2.north east) -- cycle;
\draw (m-3-3.north west) -- (m-4-3.south west) -- (m-4-4.south east) -- (m-3-4.north east) -- cycle;
\end{tikzpicture}
\end{document}
但我不知道该如何继续。
答案1
这是一个不使用 TikZ 的可能性;arydshln
包用于绘制虚线;\overmat
并\undermat
在所选条目旁边放置带有文本的上括号和下括号(\overmat
和的可选参数\undermat
允许增加条目和括号之间的垂直空间):
\documentclass{article}
\usepackage{arydshln}
\usepackage{amsmath}
\newcommand\undermat[3][0pt]{%
\makebox[0pt][l]{$\smash{\underbrace{\phantom{%
\begin{matrix}\phantom{\rule{0pt}{#1}}#3\end{matrix}}}_{\text{#2}}}$}#3}
\newcommand\overmat[3][0pt]{%
\makebox[0pt][l]{$\smash{\overbrace{\phantom{%
\begin{matrix}\phantom{\rule{0pt}{#1}}#3\end{matrix}}}^{\text{#2}}}$}#3}
\begin{document}
\[
\renewcommand\arraystretch{1.2}
\left(
\begin{array}{@{}c:cc:c:cc:c@{}}
\cdashline{2-3}\cdashline{5-6}
& \overmat[15pt]{Area I}{cpf_{11} & cpf_{12}} && \overmat[15pt]{\parbox{1.5cm}{\centering\scriptsize Area I to \\
Area II}}{cpf_{13} & cpf_{14}} & \\
\\
& cpf_{11} & cpf_{12} && cpf_{13} & cpf_{14} \\
\cdashline{2-3}\cdashline{5-6}
\multicolumn{5}{c}{} \\[-1ex]
\cdashline{2-3}\cdashline{5-6}
& cpf_{11} & cpf_{12} && cpf_{13} & cpf_{14} \\
& \undermat[15pt]{\parbox{1.5cm}{\centering\scriptsize Area II \\ to Area I}
}{cpf_{11} & cpf_{12}} && \undermat[15pt]{Area II}{cpf_{13} & cpf_{14}} \\
\cdashline{2-3}\cdashline{5-6}
\end{array}
\right)
\]
\end{document}
答案2
这是一个{pNiceMatrix}
使用 的解决方案nicematrix
。
\documentclass{article}
\usepackage{nicematrix,tikz,varwidth}
\begin{document}
$\begin{pNiceMatrix}[margin]
\Block[tikz={draw,dashed}]{2-2}{}
cpf_{11} & cpf_{12} && \Block[tikz={draw,dashed}]{2-2}{}
cpf_{13} & cpf_{14} \\
cpf_{11} & cpf_{12} && cpf_{13} & cpf_{14} \\
\\
\Block[tikz={draw,dashed}]{2-2}{}
cpf_{11} & cpf_{12} && \Block[tikz={draw,dashed}]{2-2}{}
cpf_{13} & cpf_{14} \\
cpf_{11} & cpf_{12} && cpf_{13} & cpf_{14} \\
\CodeAfter
\OverBrace[yshift=2mm]{1-1}{1-2}{\text{Area I}}
\OverBrace[yshift=2mm]{1-4}{1-5}{\begin{varwidth}{8cm}Area I to \\ \centering Area II\end{varwidth}}
\UnderBrace[yshift=2mm]{5-1}{5-2}{\begin{varwidth}{8cm}Area II to \\ \centering Area I\end{varwidth}}
\UnderBrace[yshift=2mm]{5-4}{5-5}{\text{Area II}}
\end{pNiceMatrix}$
\end{document}
在此解决方案中,我插入了一个虚拟行和一个虚拟列。没有该虚拟行和该虚拟列也是可行的。
\documentclass{article}
\usepackage{nicematrix,tikz,varwidth}
\begin{document}
\newcommand{\DashedSquare}{\Block[tikz={draw,dashed,offset=2pt}]{2-2}{}}
\renewcommand{\arraystretch}{1.3}
$\begin{pNiceMatrix}[margin]
\DashedSquare cpf_{11} & cpf_{12} & \DashedSquare cpf_{13} & cpf_{14} \\
cpf_{11} & cpf_{12} & cpf_{13} & cpf_{14} \\
\DashedSquare cpf_{11} & cpf_{12} & \DashedSquare cpf_{13} & cpf_{14} \\
cpf_{11} & cpf_{12} & cpf_{13} & cpf_{14} \\
\CodeAfter
\OverBrace[yshift=2mm,shorten=1mm]{1-1}{1-2}{\text{Area I}}
\OverBrace[yshift=2mm,shorten=1mm]{1-3}{1-4}{\begin{varwidth}{8cm}Area I to \\ \centering Area II\end{varwidth}}
\UnderBrace[yshift=2mm,shorten=1mm]{4-1}{4-2}{\begin{varwidth}{8cm}Area II to \\ \centering Area I\end{varwidth}}
\UnderBrace[yshift=2mm,shorten=1mm]{4-3}{4-4}{\text{Area II}}
\end{pNiceMatrix}$
\end{document}