![使用 kbordermatrix 标记矩阵的所有边](https://linux22.com/image/324665/%E4%BD%BF%E7%94%A8%20kbordermatrix%20%E6%A0%87%E8%AE%B0%E7%9F%A9%E9%98%B5%E7%9A%84%E6%89%80%E6%9C%89%E8%BE%B9.png)
我有一个矩阵,左侧和顶部都有标签。现在我想在矩阵的所有侧面都贴上标签。我该如何更改代码?
\documentclass[10 pt, a4paper, leqno, oneside] {report}
\usepackage{kbordermatrix}
\begin{document}
\renewcommand{\kbldelim}{(}% Left delimiter
\renewcommand{\kbrdelim}{)}% Right delimiter
\[
\tilde{\textbf{m}} = \kbordermatrix{
\mbox{} & c_1 & c_2 & c_3 & c_4 & c_5 \\
% & c_1 & c_2 & c_3 & c_4 & c_5 \\
r_1 & 1 & 1 & 1 & 1 & 1 \\
r_2 & 0 & 1 & 0 & 0 & 1 \\
r_3 & 0 & 0 & 1 & 0 & 1 \\
r_4 & 0 & 0 & 0 & 1 & 1 \\
r_5 & 0 & 0 & 0 & 0 & 1
}
\]
\end{document}
答案1
您可以使用blkarray
构建多索引数组的组件:
\documentclass{article}
\usepackage{kbordermatrix,blkarray}
\begin{document}
\renewcommand{\kbldelim}{(}% Left delimiter
\renewcommand{\kbrdelim}{)}% Right delimiter
\[
\tilde{\textbf{m}} = \kbordermatrix{
\mbox{} & c_1 & c_2 & c_3 & c_4 & c_5 \\
r_1 & 1 & 1 & 1 & 1 & 1 \\
r_2 & 0 & 1 & 0 & 0 & 1 \\
r_3 & 0 & 0 & 1 & 0 & 1 \\
r_4 & 0 & 0 & 0 & 1 & 1 \\
r_5 & 0 & 0 & 0 & 0 & 1
}
\]
\newcommand{\idxsize}{\scriptstyle}
\[
\tilde{\textbf{m}} =
\begin{blockarray}{>{\scriptstyle}c
>{\hspace{\arraycolsep}\idxsize}c*{4}{>{\idxsize}c}<{\hspace{\arraycolsep}}>{\idxsize}c}
& c_1 & c_2 & c_3 & c_4 & c_5 & \\
\begin{block}{>{\idxsize}c(>{\hspace{\arraycolsep}}ccccc<{\hspace{\arraycolsep}})>{\idxsize}c}
r_1 & 1 & 1 & 1 & 1 & 1 & r_5 \\
r_2 & 0 & 1 & 0 & 0 & 1 & r_4 \\
r_3 & 0 & 0 & 1 & 0 & 1 & r_3 \\
r_4 & 0 & 0 & 0 & 1 & 1 & r_2 \\
r_5 & 0 & 0 & 0 & 0 & 1 & r_1 \\
\end{block}
\\[-1.2\normalbaselineskip] & c_5 & c_4 & c_3 & c_2 & c_1 &
\end{blockarray}
\]
\end{document}
答案2
您可以使用 来做到这一点nicematrix
。
\documentclass{article}
\usepackage{nicematrix}
\begin{document}
\[
\tilde{\textbf{m}} =
\begin{pNiceMatrix}[first-col,last-col=6,first-row,last-row=6]
& c_1 & c_2 & c_3 & c_4 & c_5 \\
r_1 & 1 & 1 & 1 & 1 & 1 & r_5 \\
r_2 & 0 & 1 & 0 & 0 & 1 & r_4 \\
r_3 & 0 & 0 & 1 & 0 & 1 & r_3 \\
r_4 & 0 & 0 & 0 & 1 & 1 & r_2 \\
r_5 & 0 & 0 & 0 & 0 & 1 & r_1 \\
& c_5 & c_4 & c_3 & c_2 & c_1 \\
\end{pNiceMatrix}
\]
\end{document}