以下区块...
\begin{aligned}
L(\text{dn} = 1) &= P(\mathbf{A_c}, \mathbf{A_m}, \mathbf{A_f}, \mathbf{R_c}, \mathbf{R_m}, \mathbf{R_f} \mid \text{dn} = 1) \\
&= P(\mathbf{A_c}, \mathbf{A_m}, \mathbf{A_f}, \mathbf{R_c}, \mathbf{R_m}, \mathbf{R_f} \mid v_c = 0/1, v_m = 0/0, v_f = 0/0) \\
&= P(\mathbf{A_c} \mid v_c = 0/1) P(\mathbf{A_m} \mid v_m = 0/0) P(\mathbf{A_f} \mid v_f = 0/0) \\
&\quad \enskip P(\mathbf{R_c} \mid v_c = 0/1) P(\mathbf{R_m} \mid v_m = 1/1) P(\mathbf{R_f} \mid v_f = 1/1) \\
&= \prod^{n}_{i=1} P(A_{c_i} \mid v_c = 0/1) P(A_{m_i} \mid v_m = 0/0) P(A_{f_i} \mid v_f = 0/0) \\
&\quad \qquad P(R_{c_i} \mid v_c = 0/1) P(R_{m_i} \mid v_m = 1/1) P(R_{f_i} \mid v_f = 1/1)
\end{aligned}
...产生此排版结果。
第三和第四个右侧表达式太长,无法放在一行中,因此我滥用了换行符\quad
s、\qquad
s 和\enskip
s 的组合来进行对齐。尽管我付出了努力,但对齐仍然有点不对,无论如何,我更喜欢比我的肮脏黑客更干净的解决方案。
关于如何正确对齐这些表达式有什么建议吗?
答案1
您不应该不惜一切代价进行对齐:如果与前一行对齐,连续的行将会产生歧义。
我建议在最后一行添加一个运算符号来消除歧义,并添加一对括号。
我不确定粗体下标:如果它们对应垂直线的两侧,则应以相同的方式排版,因此要么全部为粗体,要么全部为斜体。这里我选择全部为斜体。如果它们应该全部为粗体(可能除了最后一行),则应该是
\mathbf{A}_{\mathbf{c}}
为了统一。我建议为这些变量定义你自己的命令,就像我下面做的那样。
\documentclass{article}
\usepackage{mathtools}
\newcommand{\bv}[1]{\mathbf{#1}}
\newcommand{\dn}{\mathrm{dn}}
\begin{document}
\begin{align*}
L(\dn = 1)
&= P(\bv{A}_c,\bv{A}_m,\bv{A}_f,\bv{R}_c,\bv{R}_m,\bv{R}_f \mid \dn = 1) \\
&= P(\bv{A}_c,\bv{A}_m,\bv{A}_f,\bv{R}_c,\bv{R}_m,\bv{R}_f \mid
v_c = 0/1, v_m = 0/0, v_f = 0/0)
\\
&= \begin{aligned}[t]
& P(\bv{A}_c \mid v_c = 0/1)
P(\bv{A}_m \mid v_m = 0/0)
P(\bv{A}_f \mid v_f = 0/0)
\\
&\cdot
P(\bv{R}_c \mid v_c = 0/1)
P(\bv{R}_m \mid v_m = 1/1)
P(\bv{R}_f \mid v_f = 1/1)
\end{aligned}
\\
&= \prod^{n}_{i=1}
\begin{aligned}[t]
\bigl(
& P(A_{c_i} \mid v_c = 0/1)
P(A_{m_i} \mid v_m = 0/0)
P(A_{f_i} \mid v_f = 0/0)
\\
&\cdot
P(R_{c_i} \mid v_c = 0/1)
P(R_{m_i} \mid v_m = 1/1)
P(R_{f_i} \mid v_f = 1/1)
\bigr)
\end{aligned}
\end{align*}
\end{document}
答案2
我认为这会产生您要求的对齐,但老实说,我不会对齐连续行,我至少会添加\quad
偏移量以更清楚地表明它们是连续的。
\documentclass{article}
\usepackage{amsmath}
\begin{document}
why not align for the outer environment?\\
$\begin{aligned}
L(\text{dn} = 1) &= P(\mathbf{A_c}, \mathbf{A_m}, \mathbf{A_f}, \mathbf{R_c}, \mathbf{R_m}, \mathbf{R_f} \mid \text{dn} = 1) \\
&= P(\mathbf{A_c}, \mathbf{A_m}, \mathbf{A_f}, \mathbf{R_c}, \mathbf{R_m}, \mathbf{R_f} \mid v_c = 0/1, v_m = 0/0, v_f = 0/0) \\
&=
\begin{aligned}[t]& P(\mathbf{A_c} \mid v_c = 0/1) P(\mathbf{A_m} \mid v_m = 0/0) P(\mathbf{A_f} \mid v_f = 0/0) \\
&P(\mathbf{R_c} \mid v_c = 0/1) P(\mathbf{R_m} \mid v_m = 1/1) P(\mathbf{R_f} \mid v_f = 1/1)
\end{aligned}\\
&= \prod^{n}_{i=1}
\begin{aligned}[t]& P(A_{c_i} \mid v_c = 0/1) P(A_{m_i} \mid v_m = 0/0) P(A_{f_i} \mid v_f = 0/0) \\
&P(R_{c_i} \mid v_c = 0/1) P(R_{m_i} \mid v_m = 1/1) P(R_{f_i} \mid v_f = 1/1)\end{aligned}
\end{aligned}$
\end{document}
答案3
只需将对齐字符 ( &
) 移到等号的右侧,即可{}
获得正确的间距(感谢 David Carlisle 的贡献!):
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{equation}
\begin{aligned}
L(\text{dn} = 1) = {}& P(\mathbf{A_c}, \mathbf{A_m}, \mathbf{A_f}, \mathbf{R_c}, \mathbf{R_m}, \mathbf{R_f} \mid \text{dn} = 1) \\
= {}& P(\mathbf{A_c}, \mathbf{A_m}, \mathbf{A_f}, \mathbf{R_c}, \mathbf{R_m}, \mathbf{R_f} \mid v_c = 0/1, v_m = 0/0, v_f = 0/0) \\
= {}& P(\mathbf{A_c} \mid v_c = 0/1) P(\mathbf{A_m} \mid v_m = 0/0) P(\mathbf{A_f} \mid v_f = 0/0) \\
{}& P(\mathbf{R_c} \mid v_c = 0/1) P(\mathbf{R_m} \mid v_m = 1/1) P(\mathbf{R_f} \mid v_f = 1/1) \\
= {}& \prod^{n}_{i=1} P(A_{c_i} \mid v_c = 0/1) P(A_{m_i} \mid v_m = 0/0) P(A_{f_i} \mid v_f = 0/0) \\
{}& P(R_{c_i} \mid v_c = 0/1) P(R_{m_i} \mid v_m = 1/1) P(R_{f_i} \mid v_f = 1/1)
\end{aligned}
\end{equation}
\end{document}
其结果将是:
答案4
对齐方程环境中的多行表达式
仔细分析问题,这是一个split
对齐方程的环境,其中两个方程是多行方程,因为它们太长并且其第二部分应该是右对齐(或右对齐,或\shoveright
,或\MoveEqRight
...)。
你需要两个嵌套multline
环境 multilined[t]
在环境内部\split
。
\documentclass{article}
\usepackage{mathtools}
\begin{document}
\begin{equation*}
\begin{split}
L((\mathrm{dn} = 1)
&= P(\mathbf{A}_c,\mathbf{A}_m,\mathbf{A}_f,\mathbf{R}_c,\mathbf{R}_m,\mathbf{R}_f \mid \mathrm{dn} = 1)
\\
&= P(\mathbf{A}_c,\mathbf{A}_m,\mathbf{A}_f,\mathbf{R}_c,\mathbf{R}_m,\mathbf{R}_f \mid
v_c = 0/1, v_m = 0/0, v_f = 0/0)
\\
&= \begin{multlined}[t]
P(\mathbf{A}_c \mid v_c = 0/1)
P(\mathbf{A}_m \mid v_m = 0/0)
P(\mathbf{A}_f \mid v_f = 0/0)
\\
\cdot
P(\mathbf{R}_c \mid v_c = 0/1)
P(\mathbf{R}_m \mid v_m = 1/1)
P(\mathbf{R}_f \mid v_f = 1/1)
\end{multlined}
\\
&= \prod^{n}_{i=1}
\begin{multlined}[t]
\bigl(P(A_{c_i} \mid v_c = 0/1)
P(A_{m_i} \mid v_m = 0/0)
P(A_{f_i} \mid v_f = 0/0)
\\
\cdot
P(R_{c_i} \mid v_c = 0/1)
P(R_{m_i} \mid v_m = 1/1)
P(R_{f_i} \mid v_f = 1/1)
\bigr)
\end{multlined}
\end{split}
\end{equation*}
\end{document}
现在看来,解决方案显而易见,但我是在花了两个小时摆弄、、、、、及其所有变体之后才找到它的;align
就在我准备联系 Lars Madsen(gather
multline
split
alginat
flalign
mathtools
)进行升级之前。它必须是具有自动化格式的东西,纯 LaTeX 风格,而不是通过使用\quad
或\hspace
或\vphantom
或类似的。
令人惊讶的是,如此基本的排版功能竟然如此鲜为人知。我的意思是,我在整个互联网上都找不到解决方案!它应该包含在指南和教程中。多行方程式在我们的日常生活中随处可见。
我知道肯定有更多的人要求解决这个问题,我现在正在整个论坛上分享这个解决方案。这也证明了该mathtools
软件包的编码有多么强大,成功地响应了这个解决方法。
享受!