行和列前的矩阵编号

行和列前的矩阵编号

我需要一些帮助,关于这个脚本:

\begin{center}
A = \begin{pmatrix}
0 & 1 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\
0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\
0 & 0 & 0 & 0 & 1 & 1 & 0 & 0 & 0 & 0 \\
0 & 0 & 1 & 0 & 0 & 0 & 0 & 1 & 1 & 0 \\
0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 1 & 0 \\
0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
\end{pmatrix}
\end{center}

我得到这个矩阵:

在此处输入图片描述

但我想要一个这样的矩阵:

在此处输入图片描述

你能帮助我吗 ?

答案1

您还可以这样做blkarray

\documentclass{article}
\usepackage{mathtools,blkarray}

\begin{document}

\[ \newcounter{rowct}\newcounter{colct}%\setlength\extrarowheight{1cm}
A =
\begin{blockarray}{*{11}{c}}
\begin{block}{r*{10}{>{\refstepcounter{colct}\mathclap{\mathbf\thecolct}}c}}
 & & & & & & & & & & \\%[-1ex]
 \end{block}
 \begin{block}{ >{\refstepcounter{rowct}\mathbf\therowct}r( >{\hspace{0.2em}}*{10}{c} <{\hspace{0.2em}})}
  &0 & 1 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \rule{0pt}{3.5ex} \\
 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\
 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\
& 0 & 0 & 0 & 0 & 1 & 1 & 0 & 0 & 0 & 0 \\
 & 0 & 1 & 0 & 0 & 0 & 0 & 1 & 1 & 0 & 0 \\
 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\
 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 1 & 0 & 0 \\
 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\[1ex]
 \end{block}
\end{blockarray}
\]
\end{document} 

在此处输入图片描述

答案2

对于这种特殊情况,一个简单的解决方法是:

\documentclass{article}
\usepackage{amsmath,stackengine}
\stackMath
\begin{document}
\[
A = 
\begin{matrix}
1\\2\\3\\4\\5\\6\\7\\8\\9\\10
\end{matrix}
\stackon[1pt]{\begin{pmatrix}
0 & 1 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\
0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\
0 & 0 & 0 & 0 & 1 & 1 & 0 & 0 & 0 & 0 \\
0 & 0 & 1 & 0 & 0 & 0 & 0 & 1 & 1 & 0 \\
0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 1 & 0 \\
0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
\end{pmatrix}
}{
\begin{matrix}
~1&2&3&4&5&6&7&8&9&10
\end{matrix}
}
\]
\end{document}

在此处输入图片描述

如果你确实想要粗体标签,

\documentclass{article}
\usepackage{amsmath,tabstackengine}
\TABstackTextstyle{\bfseries}
\setstacktabbedgap{9.2pt}
\begin{document}
\[
A = 
\tabbedCenterstack[r]{1\\2\\3\\4\\5\\6\\7\\8\\9\\10}
\stackon[1pt]{$\begin{pmatrix}
0 & 1 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\
0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\
0 & 0 & 0 & 0 & 1 & 1 & 0 & 0 & 0 & 0 \\
0 & 0 & 1 & 0 & 0 & 0 & 0 & 1 & 1 & 0 \\
0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 1 & 0 \\
0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
\end{pmatrix}$%
}{%
\;\;\tabbedCenterstack{1&2&3&4&5&6&7&8&9&10}%
}
\]
\end{document}

在此处输入图片描述

答案3

包含:{pNiceMatrix}nicematrix

\documentclass{article}
\usepackage{nicematrix}

\begin{document}

\begin{center}
$A = 
\begin{pNiceMatrix}%
  [
    first-row,
    code-for-first-row = \mathbf{\arabic{jCol}},
    first-col,
    code-for-first-col = \mathbf{\arabic{iRow}},
    columns-width=auto,
  ]
&   &   &   &   &   &   &   &   &   &   \\
& 0 & 1 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
& 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\
& 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\
& 0 & 0 & 0 & 0 & 1 & 1 & 0 & 0 & 0 & 0 \\
& 0 & 0 & 1 & 0 & 0 & 0 & 0 & 1 & 1 & 0 \\
& 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\
& 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 1 & 0 \\
& 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
& 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
& 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
\end{pNiceMatrix}$
\end{center}

\end{document}

上述代码的输出

相关内容