需要方程式对齐方面的帮助

需要方程式对齐方面的帮助

我使用了以下代码来生成两个像图中这样的方程式28和29

\begin{align}
\begin{split} \label{eq:28}
  Pr(A) ={}& (0.457 \times 1) + (0.04 \times 1) \\  ={}& 0.497 
\end{split} \\
\begin{split}
  Pr(A \ \& \ B) ={}&  (0.457 \times 1) + (0.256 \times 1) \\ 
  & + (0.157 \times 1) + (0.04 \times 1) = 0.91 \label{eq:29}
\end{split}
\end{align}

我想要的是 Pr(A) 和 Pr(A & B) 也相互对齐。有人能帮忙吗?

答案1

快速而肮脏:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align}
\begin{split} \label{eq:28}
  \rlap{$\Pr(A)$}\hphantom{\Pr(A\,\&\, B)} ={}
            & (0.457 \times 1) + (0.04 \times 1) \\
         ={}& 0.497 
\end{split} \\
\begin{split}
  \Pr(A\,\&\,B) ={}&  (0.457 \times 1) + (0.256 \times 1) \\ 
  & + (0.157 \times 1) + (0.04 \times 1) = 0.91 \label{eq:29}
\end{split}
\end{align}
\end{document}

结果

答案2

另外两种可能的布局,包括alignat

\documentclass{article}
\usepackage{mathtools}
\usepackage{stackengine}

\begin{document}
\setcounter{equation}{27}
\begin{alignat}{2}
   & \Pr(A) & & = (0.457 × 1) + (0.04 × 1) = 0.497 \\[1ex]
   & \Pr(A\,\&\,B) & & =\begin{multlined}[t] (0.457 × 1) + (0.256 × 1) \\
    + (0.157 × 1) + (0.04 × 1) = 0.91
  \end{multlined} \label{eq:29}\refstepcounter{equation} \tag*{\bllap[1.5ex]{(\theequation)}}
\end{alignat}

\begin{alignat}{3}
   & \Pr(A) & & = (0.457 × 1) + (0.04 × 1) & & = 0.497 \\[1ex]
   & \Pr(A\,\&\,B) & & = (0.457 × 1) + \mathrlap{(0.256 × 1)} \notag \\
   & & & + (0.157 × 1) + (0.04 × 1) & & = 0.91
  \label{eq:29-a}
\end{alignat}
\end{document} 

在此处输入图片描述

相关内容