我正在使用blockarray
和block
blkarray 包创建一个由 0、1 和 -1 组成的行/列索引矩阵。如何让索引居中于右对齐的列上?这就是我想要得到的:
以下是我迄今为止尝试过的 MWE:
\documentclass{article}
\usepackage{amsmath}
\usepackage{blkarray,bigstrut}
\newcommand\topstrut[1][1.2ex]{\setlength\bigstrutjot{#1}{\bigstrut[t]}}
\newcommand\botstrut[1][0.9ex]{\setlength\bigstrutjot{#1}{\bigstrut[b]}}
\begin{document}
\begin{equation*}
A_{H}=\begin{blockarray}{*{9}{c}c}
\begin{block}{*{9}{c}c}
\{a,b\} & \{b,c\} & \{c,d\} & (a,b) & (b,a) & (c,b) & (d,b) & (e,f) & (f,e) \\[-0.6ex]
\end{block}
\begin{block}{(*{9}{r})c}
1 & 0 & 0 & -1 & 1 & 0 & 0 & 0 & 0 & a \topstrut \\
1 & 1 & 0 & 1 & -1 & 1 & 1 & 0 & 0 & b \\
0 & 1 & 1 & 0 & 0 & -1 & 0 & 0 & 0 & c \\
0 & 0 & 1 & 0 & 0 & 0 & -1 & 0 & 0 & d \\
0 & 0 & 0 & 0 & 0 & 0 & 0 & -1 & 1 & e \\
0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & -1 & f \botstrut \\
\end{block}
\end{blockarray}
\end{equation*}
\end{document}
并产生:
答案1
它是很多更容易nicematrix
:
\documentclass{article}
\usepackage{amsmath}
\usepackage{nicematrix,siunitx}
\begin{document}
\begin{equation*}
A_{H}=
\begin{pNiceArray}{*{9}{S[table-format=-1.0]}}[first-row,last-col,code-for-last-col=\enspace]
{\{a,b\}} &
{\{b,c\}} &
{\{c,d\}} &
{(a,b)} &
{(b,a)} &
{(c,b)} &
{(d,b)} &
{(e,f)} &
{(f,e)} &
\\
1 & 0 & 0 & -1 & 1 & 0 & 0 & 0 & 0 & a \\
1 & 1 & 0 & 1 & -1 & 1 & 1 & 0 & 0 & b \\
0 & 1 & 1 & 0 & 0 & -1 & 0 & 0 & 0 & c \\
0 & 0 & 1 & 0 & 0 & 0 & -1 & 0 & 0 & d \\
0 & 0 & 0 & 0 & 0 & 0 & 0 & -1 & 1 & e \\
0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & -1 & f \\
\end{pNiceArray}
\end{equation*}
\end{document}
答案2
使用肮脏的伎俩——将 r
“\quad”空间的列移到左边:
\documentclass{article}
\usepackage{blkarray,bigstrut}
\newcommand\topstrut[1][1.2ex]{\setlength\bigstrutjot{#1}{\bigstrut[t]}}
\newcommand\botstrut[1][0.9ex]{\setlength\bigstrutjot{#1}{\bigstrut[b]}}
\begin{document}
\[
A_{H}=\begin{blockarray}{*{9}{c}c}
\begin{block}{*{9}{c}c}
\{a,b\} & \{b,c\} & \{c,d\} & (a,b) & (b,a) & (c,b) & (d,b) & (e,f) & (f,e) \\[-0.6ex]
\end{block}
\begin{block}{(*{9}{r<{\quad}})c} % <---
1 & 0 & 0 & -1 & 1 & 0 & 0 & 0 & 0 & a \topstrut \\
1 & 1 & 0 & 1 & -1 & 1 & 1 & 0 & 0 & b \\
0 & 1 & 1 & 0 & 0 & -1 & 0 & 0 & 0 & c \\
0 & 0 & 1 & 0 & 0 & 0 & -1 & 0 & 0 & d \\
0 & 0 & 0 & 0 & 0 & 0 & 0 & -1 & 1 & e \\
0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & -1 & f \botstrut \\
\end{block}
\end{blockarray}
\]
\end{document}
答案3
无需制作blkarray
并使用siunitx
的S
列用于围绕负数进行对齐:
\documentclass{article}
\usepackage{amsmath,siunitx}
\begin{document}
\[
A_H =
% Left bracket
\left( \begin{array}{ @{} l @{} } \mathstrut \\ \mathstrut \\ \mathstrut \\ \mathstrut \\ \mathstrut \\ \mathstrut \end{array} \right.
\kern-\nulldelimiterspace
% Center matrix and column indices
\raisebox{.5\baselineskip}{$\begin{array}{ @{} *{3}{c} *{6}{ S[table-format = -1] } @{} }
{\{a, b\}} & {\{b, c\}} & {\{c, d\}} & {(a, b)} & {(b, a)} & {(c, d)} & {(d, b)} & {(e, f)} & {(f, e)} \\
1 & 0 & 0 & -1 & 1 & 0 & 0 & 0 & 0 \\
1 & 1 & 0 & 1 & -1 & 1 & 1 & 0 & 0 \\
0 & 1 & 1 & 0 & 0 & -1 & 0 & 0 & 0 \\
0 & 0 & 1 & 0 & 0 & 0 & -1 & 0 & 0 \\
0 & 0 & 0 & 0 & 0 & 0 & 0 & -1 & 1 \\
0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & -1 \\
\end{array}$}
% Right bracket and row indices
\left) \begin{array}{ c @{} } a \\ b \\ c \\ d \\ e \\ f \end{array} \right.
\]
\end{document}