加载数组包时,表格两侧添加 \mathsurround

加载数组包时,表格两侧添加 \mathsurround

当长度\mathsurround取非零值,并且使用某些包(array、和其他包)时,将在表格的两边插入tabularx等于的空格。\mathsurround

为什么会出现这样的行为?有没有办法可以避免它(除了使用\AtBeginEnvironment{...}{mathsurround=0pt})?

以下是 MWE:

\documentclass{article}
\usepackage[showframe]{geometry}

\mathsurround=50pt % Exaggerated value to visualize the effect

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Each of the following packages adds a space equal to "\mathsurround" on either side of the table. Uncomment to see the effect.

% \usepackage{array}
% \usepackage{siunitx}
% \usepackage{cellspace}
% \usepackage{makecell}
% \usepackage{nicematrix}
% \usepackage{tabularx}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}

Bla bla $x=0$ bla bla.

Bla bla
\begin{tabular}{|c|}\hline
    A\\\hline
\end{tabular}
bla bla.

\begin{table}[!h]
    \begin{tabular}{|c|}\hline
        A\\\hline
    \end{tabular}
\end{table}
\end{document}

答案1

我认为这从一开始就存在,这似乎有点令人惊讶,\m@th\mathsurround似乎被错误地重置了array.sty

在此处输入图片描述

\documentclass{article}
\usepackage[showframe]{geometry}

\mathsurround=50pt % Exaggerated value to visualize the effect


\usepackage{array}

\begin{document}

Bla bla $x=0$ bla bla.


X\begin{tabular}{|c|}A$x$A\end{tabular}X

\makeatletter
\def\endtabular{\endarray\m@th$\egroup}
\makeatother


X\begin{tabular}{|c|}A$x$A\end{tabular}X


\end{document}

相关内容