枚举方程对齐

枚举方程对齐

在此处输入图片描述

我唯一想到的办法就是使用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 和lapping 的混合。在您的设置中,a比 宽ba + 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(看另一个答案\label) 通过使用 LaTeX 的-\ref系统通过 捕获最宽元素的宽度\eqmakebox[<tag>][<align>]{<stuff>}

相关内容