方程式中的水平間距

方程式中的水平間距

我正在嘗試複製與簡單數學模式給出的簡單多項式公式相同的精確輸出,但使用它是\matrix因為我想右對齊多項式中的項或將其中一些項留空。\alignat由於其他原因我無法使用其中任何一個。

我已經取得了一些進展,但間距很難正確。在下圖中,您可以看到簡單數學模式下的輸出,使用 \alignat和我的嘗試使用\matrix(我使用便利巨集 \arr)。

在此輸入影像描述

正如你所看到的,我的版本有些偏差。我認為最大的錯誤在於等號周圍的間距。

\documentclass[a4paper,11pt]{article}
\usepackage{amsmath}
\makeatletter
% http://tex.stackexchange.com/questions/2233/
\renewcommand*\env@matrix[1][*\c@MaxMatrixCols r]{%
  \hskip -\arraycolsep
  \let\@ifnextchar\new@ifnextchar
  \array{#1}}
\newcommand{\arr}{\@ifstar\arr@star\arr@nostar}
\newcommand{\arr@nostar}[2][*\c@MaxMatrixCols r]{%
  \begin{bmatrix}[#1]#2\end{bmatrix}%
}
\newcommand{\arr@star}[2][*\c@MaxMatrixCols r]{%
  \begin{matrix}[#1]#2\end{matrix}%
}
\makeatother

\begin{document}

\begin{equation}
  C + 3D = 2
\end{equation}
%
\begin{alignat}{3}
  C  &+{}& 3D &={}& 2 & \notag
\end{alignat}
%
\begin{equation}
  \arr*[@{}r@{\,}c@{\,}r@{\,}c@{\,}r@{}]{
    C  &+{}& 3D &=& 2 \notag
  }
\end{equation}

\end{document}

答案1

您會考慮使用表格堆疊作為一種選擇嗎?

這裡我用一次性呼叫來設定它:

\usepackage{tabstackengine}
\stackMath
\setstacktabulargap{0pt}
\TABbinary

然後我使用模仿表格分隔符號的語法呼叫各種形式的表格堆疊之一。

\documentclass[a4paper,11pt]{article}
\usepackage{amsmath}
\usepackage{tabstackengine}
\stackMath
\setstacktabulargap{0pt}
\TABbinary
\begin{document}

\begin{equation}
  C + 3D = 2
\end{equation}
%
\begin{alignat}{3}
  C  &+{}& 3D &={}& 2 & \notag
\end{alignat}
%
\begin{equation}
  \tabularCenterstack{rcrcr}{
  C&+&3D&=&2
  }
\end{equation}
\begin{equation}
  \tabularCenterstack{rcrcr}{
  C&+&3D&=&2\\
  4C&-&D&=&27
  }
\end{equation}
\end{document}

在此輸入影像描述

相關內容