如题所述,希望对矩阵排版实现下面的需求:
上述需求在书写一个算符在一组特定的基(basis)的矩阵形式的时候自然而然的产生:标签和列标签用于明确基,而分块“可以”用于划分特定的子空间。
为了明确上述需求,下面给出一个针对 3x3 矩阵的 MWE。我可以很容易使用 blockarray
实现第一个需求,但第二个需求的实现尚不完善。
\documentclass{article}
\usepackage{amsmath}
\usepackage{blkarray}
\usepackage{tikz}
\usepackage{nicematrix}
\begin{document}
\begin{equation*}
\begin{blockarray}{c *{3}{c}} % c for row label, ccc for matrix columns
{} & \text{Col 1} & \text{Col 2} & \text{Col 3} \\
\begin{block}{c [*{3}{c}]} % c for row label, [ccc] for bracketed matrix
\text{Row 1} & 1 & 2 & 3 \\
\text{Row 2} & 4 & 5 & 6 \\
\text{Row 3} & 7 & 8 & 9 \\
\end{block}
\end{blockarray}
\end{equation*}
\begin{equation*}
\begin{bNiceArray}{cc|c}[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*}
不做解释了,最后一种是我认为的最佳实践
\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}