通常,我们将矩阵类型为\begin{pmatrix} ... \end{pmatrix}
。但是,pmatrix
最多限制为 10 列。如果矩阵包含更多列,则会出错! Extra alignment tab has been changed to \cr.
。
作为替代,我使用了\left(\begin{array}{cc...c} ... \end{array}\right)
。但结果并不完全相同:在开始括号的右侧和结束括号的左侧有更多的空间。
pmatrix
精确重现多列矩阵的间距行为的最简单/首选方法是什么?
答案1
中的最大列数{pmatrix}
由 LaTeX 计数器设置\MaxMatrixCols
。您可以使用以下方法更改其值\setcounter
:
\setcounter{MaxMatrixCols}{20}
另一方面,如果您想要{array}
与 有相同的间距{pmatrix}
,请@{}
在序言中使用:
\left(\begin{array}{@{}cc@{}} a & b \\ c & d \end{array}\right)
答案2
您还可以使用+pmatrix
(最近的)tabularray
包:
\documentclass{article}
\usepackage{tabularray}
\UseTblrLibrary{amsmath}
\begin{document}
An ordinary \texttt{pmatrix}:
\[
\begin{pmatrix}
1 & 2 & 3 \\
3 & 2 & 1 \\
2 & -1 & -3 \\
\end{pmatrix}
\]
A \texttt{+pmatrix} from \texttt{tabularray} package:
\[
\begin{+pmatrix}
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\
3 & 2 & 11 & 2 & 31 & 2 & 31 & 2 & 3 & -3 & -4 & 15 \\
2 & -1 & -3 1 & 2 & 3 1 & 2 & 3 1 & 2 & 3 & -3 & 5 & -16\\
\end{+pmatrix}
\]
Note that \texttt{+pmatrix} has a better row spacing compared with \texttt{pmatrix}.
Compare these examples taken from the \texttt{tabularray} package documentation:
\[
\begin{pmatrix}
\dfrac{2}{3} & \dfrac{2}{3} & \dfrac{1}{3} \\
\dfrac{2}{3} & -\dfrac{1}{3} & -\dfrac{2}{3} \\
\dfrac{1}{3} & -\dfrac{2}{3} & \dfrac{2}{3} \\
\end{pmatrix}
\]
\[
\begin{+pmatrix}
\dfrac{2}{3} & \dfrac{2}{3} & \dfrac{1}{3} \\
\dfrac{2}{3} & -\dfrac{1}{3} & -\dfrac{2}{3} \\
\dfrac{1}{3} & -\dfrac{2}{3} & \dfrac{2}{3} \\
\end{+pmatrix}
\]
However, if you want the original spacing, you can set it. Compare the followings with the first example of this page.
\[
\begin{+pmatrix}
1 & 2 & 3 \\
3 & 2 & 1 \\
2 & -1 & -3 \\
\end{+pmatrix}
\]
\[
\begin{+pmatrix}[abovesep=0pt, belowsep=0pt]
1 & 2 & 3 \\
3 & 2 & 1 \\
2 & -1 & -3 \\
\end{+pmatrix}
\]
\end{document}