5 如何同时给矩阵添加行标签、列标签并使用虚线给矩阵分块?

发布于 2025-08-25 12:47:35

问题描述

如题所述,希望对矩阵排版实现下面的需求:

  • 给矩阵添加行标签和列标签,且标签应该位于矩阵的圆括号或者方括号的外部;
  • 使用虚线给矩阵分块,虚线不应越过矩阵的圆括号或者方括号围成的区域。

问题背景

上述需求在书写一个算符在一组特定的基(basis)的矩阵形式的时候自然而然的产生:标签和列标签用于明确基,而分块“可以”用于划分特定的子空间。

MWE

为了明确上述需求,下面给出一个针对 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*}

image.png

查看更多

关注者
0
被浏览
73
Sagittarius Rover
Sagittarius Rover 9小时前
这家伙很懒,什么也没写!

不做解释了,最后一种是我认为的最佳实践

\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}

image.png

1 个回答

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览