将等式的最后一部分也左对齐

将等式的最后一部分也左对齐

我有以下等式:

\begin{flalign*}
p(C = c_1 | X = t) &= \frac{p(X = t | C = c_1) p(C = c_1)}{p(X = t)} &= \frac{\theta_1 \pi_1}{\theta_1 \pi_1 + \theta_2 (1 - \pi_1)} \\
p(C = c_1 | X = h) &= \frac{p(X = h | C = c_1) p(C = c_1)}{p(X = h)} &= \frac{(1 - \theta_1) \pi_1}{(1 - \theta_1) \pi_1 + (1 - \theta_2) (1 - \pi_1)}
\end{flalign*}

它们看起来像这样:

That's not how I want it

但我希望最右边的部分与左侧对齐。特别是,我希望最后两个等号对齐,并尽可能向左移动,将公式的最后一部分拖到它们一起。我该怎么做?

答案1

下次请发布完整的工作示例。

您需要添加第二个 &。它总是在右对齐和左对齐之间交替。

\documentclass{article}
\usepackage{amsmath}
\begin{document}
    \begin{flalign*}
    p(C = c_1 | X = t) &= \frac{p(X = t | C = c_1) p(C = c_1)}{p(X = t)} &&= \frac{\theta_1 \pi_1}{\theta_1 \pi_1 + \theta_2 (1 - \pi_1)} \\
    p(C = c_1 | X = h) &= \frac{p(X = h | C = c_1) p(C = c_1)}{p(X = h)} &&= \frac{(1 - \theta_1) \pi_1}{(1 - \theta_1) \pi_1 + (1 - \theta_2) (1 - \pi_1)}
    \end{flalign*}
\end{document}

enter image description here

编辑:要去掉最后一个等式符号之前的空格,请使用alignategreg 建议的环境。

\documentclass{article}
\usepackage{amsmath}
\begin{document}
    \begin{alignat*}{2}
    p(C = c_1 | X = t) &= \frac{p(X = t | C = c_1) p(C = c_1)}{p(X = t)} &&= \frac{\theta_1 \pi_1}{\theta_1 \pi_1 + \theta_2 (1 - \pi_1)} \\
    p(C = c_1 | X = h) &= \frac{p(X = h | C = c_1) p(C = c_1)}{p(X = h)} &&= \frac{(1 - \theta_1) \pi_1}{(1 - \theta_1) \pi_1 + (1 - \theta_2) (1 - \pi_1)}
    \end{alignat*}
\end{document}

enter image description here

相关内容