不做解释了,最后一种是我认为的最佳实践
\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usepackage{nicematrix}
\begin{document}
\begin{equation*}
\begin{bNiceArray}{ccc}[first-row,first-col]
& \text{Col 1} & \text{Col 2} & \text{Col 3} \\
\text{Row 1} & 1 & 2 & 3 \\
\text{Row 2} & 4 & 5 & 6 \\
\Hline
\text{Row 3} & 7 & 8 & 9 \\
\end{bNiceArray}
\end{equation*}
\begin{equation*}
\begin{bNiceArray}{cc|[tikz=dashed,color=red]c}[first-row,first-col,margin]
& \text{Col 1} & \text{Col 2} & \text{Col 3} \\
\text{Row 1} & 1 & 2 & 3 \\
\text{Row 2} & 4 & 5 & 6 \\
\Hline
\text{Row 3} & 7 & 8 & 9 \\
\end{bNiceArray}
\end{equation*}
\begin{equation*}
\begin{bNiceArray}{cc|[tikz=dashed]c}[first-row,first-col,margin]
& \text{Col 1} & \text{Col 2} & \text{Col 3} \\
\text{Row 1} & \Block[borders={bottom,right,tikz=dashed}]{2-2}{}
1 & 2 & 3 \\
\text{Row 2} & 4 & 5 & 6 \\
\text{Row 3} & 7 & 8 &\Block[borders={left,top,tikz=dashed}]{1-1}{} 9 \\
\end{bNiceArray}
\end{equation*}
\begin{equation*}
\begin{bNiceArray}{cc|[tikz=dashed,color=violet]c}[first-row,first-col,margin]
& \text{Col 1} & \text{Col 2} & \text{Col 3} \\
\text{Row 1} & 1 & 2 & 3 \\
\text{Row 2} & 4 & 5 & 6 \\
\Hline[tikz=dashed,color=orange]
\text{Row 3} & 7 & 8 & 9 \\
\end{bNiceArray}
\end{equation*}
\end{document}
问 如何同时给矩阵添加行标签、列标签并使用虚线给矩阵分块?