枚舉方程式對齊

枚舉方程式對齊

在此輸入影像描述

我唯一想到的是使用intertext並手動放置計數器。這真的是唯一的方法嗎?

答案1

您可以使用\intertext

\documentclass{article}
\usepackage{mathtools}

\begin{document}

\begin{enumerate}\mathtoolsset{above-intertext-sep=-\belowdisplayshortskip}
\item How can I align the equations
\begin{align*}
    a &= 2. \\
\intertext{
  \item Which appear in various items of \texttt{enumerate}?
}
  b &= a + 123.
\end{align*}
\end{enumerate}

\end{document}

在此輸入影像描述

答案2

您可以使用eqparbox

\documentclass{article}
\usepackage{amsmath}
\usepackage{eqparbox}
\begin{document}
\begin{enumerate}
 \item How can I align the equation
 \begin{align*}
  \eqmakebox[L][r]{$a$}&=\eqmakebox[R][l]{$2$}
 \end{align*}
 \item with the equation
 \begin{align*}
  \eqmakebox[L][r]{$b$}&=\eqmakebox[R][l]{$a+123$}
 \end{align*} 
 \item With \verb|eqparbox|.
\end{enumerate}
You can make it more structured by defining macros for that.
\newcommand{\LHS}[2][pft]{\eqmakebox[L#1][r]{$\displaystyle #2$}}
\newcommand{\RHS}[2][pft]{\eqmakebox[R][l]{$\displaystyle #2$}}
\begin{enumerate}
 \item Now you can align the equation
 \begin{align*}
  \LHS{a}&=\RHS{2}
 \end{align*}
 \item with the equation
 \begin{align*}
  \LHS{b+7c}&=\RHS{a+123}
 \end{align*} 
 \item using the macros \verb|\LHS| and \verb|\RHS|.
\end{enumerate}
The optional argument is an identifier. For each new set of mutually aligned
equations you need a distinct identifier. That is, all the left--hand sides and
all the right--hand sides with the same identifier have the same widths,
respectively.
\end{document}

在此輸入影像描述

附錄: 這是一個補充egreg 的好(!)解決方案。如果您考慮加載enumitem(在 之上mathtools),您可以通過說來使事情變得更加用戶友好

\setlist[enumerate]{before=\mathtoolsset{above-intertext-sep=-\belowdisplayshortskip}}

這樣您就不必手動將其新增至每個enumerate環境。

\documentclass{article}
\usepackage{mathtools}
\usepackage{enumitem}
\setlist[enumerate]{before=\mathtoolsset{above-intertext-sep=-\belowdisplayshortskip}}
\begin{document}

\begin{enumerate}
\item How can I align the equations
\begin{align*}
    a &= 2 \;,\\
\intertext{
  \item which appear in various items of \texttt{enumerate},
}
  b &= a + 123\;,\\
\intertext{
  \item and without adding something by hand whenever I use \texttt{enumerate}?
}
  b &= c + d+\frac{7\pi}{2}\;.
\end{align*}
\end{enumerate}

\begin{align}
a &= 2 \;.\\
\intertext{We're back to normal.}
 b &= a + 123\;.
\end{align}
\end{document}

在此輸入影像描述

答案3

您需要能夠存取每個方程式左側和右側最寬的元素,並混合使用\phantoms 和 over lapping。在您的設定中,a比 更寬b,並且a + 123比 更寬2.,所以

在此輸入影像描述

\documentclass{article}

\usepackage{mathtools}

\begin{document}

\begin{enumerate}
  \item
  How can I align the equations
  \[
    a = \mathrlap{2.}\phantom{a + 123}% Widest RHS is "a + 123"
  \]

  \item
  Which appear in various items of \verb|enumerate|?
  \[
    \phantom{a}\mathllap{b} = a + 123 % Widest LHS is "a"
  \]
\end{enumerate}

\end{document}

上述過程簡化為eqparbox(看另一個答案)透過使用 LaTeX 的系統\label捕獲最寬元素的寬度。\ref\eqmakebox[<tag>][<align>]{<stuff>}

相關內容