我怎样才能将字母放在矩阵每列的顶部?

我怎样才能将字母放在矩阵每列的顶部?

在此处输入图片描述

\documentclass{article}
\usepackage{amsmath,booktabs}

\begin{document}

\[

\implies
\mathbf{B}^c=
\begin{bmatrix}

\begin{array}{@{}ccc|ccc|c@{}}


\mathbf{-I} & \mathbf{0} & \mathbf{0} & \mathbf{I} & \mathbf{0} & \mathbf{0} & \mathbf{0} \\
\mathbf{0} & \mathbf{-I} & \mathbf{0} & \mathbf{0} & \mathbf{I} & \mathbf{0} & \mathbf{0}\\
 \mathbf{0} & \mathbf{0} & \mathbf{-I} & \mathbf{0} & \mathbf{0} & \mathbf{I} & \mathbf{0}\\
 \mathbf{0} & \mathbf{0} & \mathbf{0} & \mathbf{-I} & \mathbf{0} & \mathbf{0} & \mathbf{I}\\
 \end{array}
 \end{bmatrix}

 \]

\end{document}

答案1

包含:{pNiceArray}nicematrix

\documentclass{article}
\usepackage{amsmath,booktabs}
\usepackage{nicematrix}

\begin{document}

\[
\mathbf{B}^c=
\begin{bNiceArray}{ccc|ccc|c}[first-row]
\mathbf{u}_c^{\mathbf{N}} & \mathbf{u}_e^{\mathbf{N}} & \mathbf{u}_o^{\mathbf{N}} 
& \mathbf{u}_c^{\mathbf{R}}&\mathbf{u}_e^{\mathbf{R}} & \mathbf{u}_o^{\mathbf{R}}
& \mathbf{u}_c^{\mathbf{OV}} \\
\mathbf{-I} & \mathbf{0} & \mathbf{0} & \mathbf{I} & \mathbf{0} & \mathbf{0} & \mathbf{0} \\
\mathbf{0} & \mathbf{-I} & \mathbf{0} & \mathbf{0} & \mathbf{I} & \mathbf{0} & \mathbf{0}\\
 \mathbf{0} & \mathbf{0} & \mathbf{-I} & \mathbf{0} & \mathbf{0} & \mathbf{I} & \mathbf{0}\\
 \mathbf{0} & \mathbf{0} & \mathbf{0} & \mathbf{-I} & \mathbf{0} & \mathbf{0} & \mathbf{I}\\
 \end{bNiceArray}
 \]

\end{document}

上述代码的输出

答案2

blkarray可以成为你的朋友。下面是它的一个使用示例(摘自黑白阵列):

\documentclass{article}
\usepackage{blkarray}
\begin{document}
\[
\begin{blockarray}{ccccc}
      & A & B & C & D\\
    \begin{block}{c[cccc]}
    A & 1 & 1 & 1 & 1\\ 
    B & 1 & 0 & 0 & 1\\
    C & 1 & 0 & 1 & 1\\
    D & 1 & 1 & 1 & 0\\
    \end{block}
  \end{blockarray}
\]
\end{document} 

在此处输入图片描述

您只需用您的数据替换单元格的内容并在矩阵中添加缺失的列。

相关内容