负号和矩阵对齐

负号和矩阵对齐

我无法将矩阵元素居中,因此对齐时不会考虑负号。此外,我还希望左括号和最左列左边缘之间的空间等于右括号和最右列右边缘之间的空间。我该如何排版矩阵以满足这些视觉约束?

这里有一个关联找到一份描述该问题的文档。来源如下:

\documentclass[11pt,a4paper]{article}
\usepackage{amsmath}
\usepackage{mathtools}

\begin{document}

\noindent This document provides some examples of matrices for which I cannot
get the elements to line up as I would like.

\bigskip

\noindent\textbf{Example.} I would like the numbers in the matrix $A$ to be
centered, but I do not want the negative sign to cause numbers to be shifted. In
other words, I am looking for something along the lines of a ``center, but
ignore the negative sign'' environment. For example, consider the matrix
\[
    A = \begin{pmatrix*}
    -1 & -10 & 1 \\
    100 & 5 & 16 \\
    13 & 7 & 7
    \end{pmatrix*}.
\]
One common suggestion I have read advises to instead use the array environment,
along with the right-align option. However, there are still problems. Consider
the matrices
\[
    A = \left(\begin{array}{rrr}
    -1 & -2 & -3 \\
    4 & 5 & 6 \\
    -7 & -8 & -9
    \end{array}\right), \quad\text{and}\quad
    B = \left(\begin{array}{rrr}
    -1 & -10 & 1 \\
    100 & 5 & 16 \\
    13 & 7 & 7
    \end{array}\right).
\]
Since the elements of $A$ are all single digits, the alignment is satisfactory. Using the right-alignment hack does not do much good for
matrix $B$, where the elements have different digit lengths.

\bigskip

\noindent How can I center the elements of a matrix so that the negative sign
does not have any influence on alignment, and so that the space between the left
parenthesis and left edge the leftmost column of numbers equals the space
between the right parenthesis and the right edge of the rightmost column of
numbers?

\end{document}

感谢您的帮助!

答案1

我认为问题在于减号的宽度太大,比数字还大。因此,在居中对齐时,减号会变得更重。

以下示例仅使用减号的数字宽度进行对齐,并将减号的总宽度减少为数字宽度的 110%。通常数字左侧有足够的空白,因此突出不会造成太大影响。

\documentclass[11pt,a4paper]{article}
\usepackage{amsmath}
\usepackage{mathtools}

\usepackage{graphicx}
\newcommand*{\matminus}{%
  \leavevmode
  \hphantom{0}%
  \llap{%
    \settowidth{\dimen0 }{$0$}%
    \resizebox{1.1\dimen0 }{\height}{$-$}%
  }%
}

\begin{document}

\[
    A = \begin{pmatrix*}
    \matminus1 & \matminus10 & 1 \\
    100 & 5 & 16 \\
    13 & 7 & 7
    \end{pmatrix*}.
\]

\end{document}

结果

上述建议是在不同要求之间的折衷。当然,数字也可以居中而不考虑减号,也不会改变列边距。但这样单元格条目就不再独立了,排版取决于其他行中的值:

  • \llap{$-$}设置减号并让 TeX 认为宽度为零。这符合居中要求。但根据其他行中的其他值,需要在列左侧插入额外的空白。
  • \hphantom{-}不设置减号,只设置水平空间。它可以帮助正确对齐正数和负数,但可能需要根据列中的其他值减少列左侧的空白。

相关内容