LaTeX 中的对齐环境错误

LaTeX 中的对齐环境错误

我在 latex 中有以下数学方程,我想将其对齐,但是当我编译代码时,没有得到结果,也没有错误消息。有人能帮我修复代码吗?

\begin{align}
 \alpha &= \frac{p(θ^{*},x_{1:T}^{*}|y_{1:T})}{p(θ^{t},x_{1:T}^{t}|y_{1:T})}\frac{q(θ^{t},x_{1:T}^{t}|θ^{*},x_{1:T}^{*})}{q(θ^{*},x_{1:T}^{*}|θ^{t},x_{1:T}^{t})}\\
    &=  \frac{p(θ^{*},x_{1:T}^{*}|y_{1:T})}{p(θ^{t},x_{1:T}^{t}|y_{1:T})}\frac{q(θ^{t}|θ^{*})}{q(θ^{*}|θ^{t})}\frac{q(x_{1:T}^{t}|y_{1:T}^{t},θ^{t})}{q(x_{1:T}^{*}|y_{1:T}^{*},θ^{*})}\\
    &= \frac{p(x_{1:T}^{*}|y_{1:T},θ^{*})}{p(x_{1:T}^{t}|y_{1:T},θ^{t})}\frac{p(\theta^{*}|y_{1:T})}{p(\theta^{t}|y_{1:T})}\frac{q(θ^{t}|θ^{*})}{q(θ^{*}|θ^{t})}\frac{q(x_{1:T}^{t}|y_{1:T}^{t},θ^{t})}{q(x_{1:T}^{*}|y_{1:T}^{*},θ^{*})}\\
    &= \frac{p(\theta^{*}|y_{1:T})}{p(\theta^{t}|y_{1:T})}\frac{q(θ^{t}|θ^{*})}{q(θ^{*}|θ^{t})}\\
   & = \frac{p(y_{1:T}|\theta^{*}}{p(y_{1:T}|\theta^{t}}\frac{\theta^{*}}{\theta{t}}\frac{q(θ^{t}|θ^{*})}{q(θ^{*}|θ^{t})
\end{align}

答案1

最后,就在之前,缺少了一个支架\end{align}

我是怎么找到它的?我按照以下方式重写了代码,以便可以直观地控制分子和分母

\documentclass{article}
\usepackage{amsmath}

\DeclareUnicodeCharacter{03B8}{\theta}

\begin{document}

\begin{align}
  \alpha
  &= \frac{p(θ^{*},x_{1:T}^{*}|y_{1:T})}
          {p(θ^{t},x_{1:T}^{t}|y_{1:T})}
     \frac{q(θ^{t},x_{1:T}^{t}|θ^{*},x_{1:T}^{*})}
          {q(θ^{*},x_{1:T}^{*}|θ^{t},x_{1:T}^{t})}
  \\
  &= \frac{p(θ^{*},x_{1:T}^{*}|y_{1:T})}
          {p(θ^{t},x_{1:T}^{t}|y_{1:T})}
     \frac{q(θ^{t}|θ^{*})}{q(θ^{*}|θ^{t})}
     \frac{q(x_{1:T}^{t}|y_{1:T}^{t},θ^{t})}
          {q(x_{1:T}^{*}|y_{1:T}^{*},θ^{*})}\\
  &= \frac{p(x_{1:T}^{*}|y_{1:T},θ^{*})}
          {p(x_{1:T}^{t}|y_{1:T},θ^{t})}
     \frac{p(\theta^{*}|y_{1:T})}
          {p(\theta^{t}|y_{1:T})}
     \frac{q(θ^{t}|θ^{*})}{q(θ^{*}|θ^{t})}
     \frac{q(x_{1:T}^{t}|y_{1:T}^{t},θ^{t})}
          {q(x_{1:T}^{*}|y_{1:T}^{*},θ^{*})}
  \\
  &= \frac{p(\theta^{*}|y_{1:T})}
          {p(\theta^{t}|y_{1:T})}
     \frac{q(θ^{t}|θ^{*})}{q(θ^{*}|θ^{t})}
  \\
  &= \frac{p(y_{1:T}|\theta^{*}}
          {p(y_{1:T}|\theta^{t}}
     \frac{\theta^{*}}{\theta{t}}
     \frac{q(θ^{t}|θ^{*})}{q(θ^{*}|θ^{t})} % <---
\end{align}

\end{document}

并且缺少括号(此处用 表示<---)变得明显。添加后,我运行 LaTeX 时没有出现任何错误。

不过,我不确定您是否想要align,因为对每行进行编号似乎没有必要。无论如何,您自己决定。

我也不建议在θ和之间交替\theta:这会使打字稿混乱且可读性较差。

在此处输入图片描述

使用\mid而不是|可能会使得事物不那么紧凑。

在此处输入图片描述

答案2

请始终显示完整文档,而不仅仅是片段

\documentclass{article}

\usepackage{amsmath}

\begin{document}
\begin{align}
 \alpha &= \frac{p(θ^{*},x_{1:T}^{*}|y_{1:T})}{p(θ^{t},x_{1:T}^{t}|y_{1:T})}\frac{q(θ^{t},x_{1:T}^{t}|θ^{*},x_{1:T}^{*})}{q(θ^{*},x_{1:T}^{*}|θ^{t},x_{1:T}^{t})}\\
    &=  \frac{p(θ^{*},x_{1:T}^{*}|y_{1:T})}{p(θ^{t},x_{1:T}^{t}|y_{1:T})}\frac{q(θ^{t}|θ^{*})}{q(θ^{*}|θ^{t})}\frac{q(x_{1:T}^{t}|y_{1:T}^{t},θ^{t})}{q(x_{1:T}^{*}|y_{1:T}^{*},θ^{*})}\\
    &= \frac{p(x_{1:T}^{*}|y_{1:T},θ^{*})}{p(x_{1:T}^{t}|y_{1:T},θ^{t})}\frac{p(\theta^{*}|y_{1:T})}{p(\theta^{t}|y_{1:T})}\frac{q(θ^{t}|θ^{*})}{q(θ^{*}|θ^{t})}\frac{q(x_{1:T}^{t}|y_{1:T}^{t},θ^{t})}{q(x_{1:T}^{*}|y_{1:T}^{*},θ^{*})}\\
    &= \frac{p(\theta^{*}|y_{1:T})}{p(\theta^{t}|y_{1:T})}\frac{q(θ^{t}|θ^{*})}{q(θ^{*}|θ^{t})}\\
   & = \frac{p(y_{1:T}|\theta^{*}}{p(y_{1:T}|\theta^{t}}\frac{\theta^{*}}{\theta{t}}\frac{q(θ^{t}|θ^{*})}{q(θ^{*}|θ^{t})
\end{align}
\end{document}

生产

Runaway argument?
 \alpha &= \frac {p(θ^{*},x_{1:T}^{*}|y_{1:T})}{p(θ^{t},x_{1:T}^{t}\ETC.
! File ended while scanning use of \align.
<inserted text> 
                \par 
<*> cc460
         
? 

由于牙套不匹配

添加一些} 产品

! LaTeX Error: Unicode character θ (U+03B8)
               not set up for use with LaTeX.

默认情况下你不能直接使用希腊语,而是使用\theta希腊语进行数学运算

\documentclass{article}

\usepackage{amsmath}

\begin{document}
\begin{align}
 \alpha &= \frac{p(\theta^{*},x_{1:T}^{*}|y_{1:T})}{p(\theta^{t},x_{1:T}^{t}|y_{1:T})}\frac{q(\theta^{t},x_{1:T}^{t}|\theta^{*},x_{1:T}^{*})}{q(\theta^{*},x_{1:T}^{*}|\theta^{t},x_{1:T}^{t})}\\
    &=  \frac{p(\theta^{*},x_{1:T}^{*}|y_{1:T})}{p(\theta^{t},x_{1:T}^{t}|y_{1:T})}\frac{q(\theta^{t}|\theta^{*})}{q(\theta^{*}|\theta^{t})}\frac{q(x_{1:T}^{t}|y_{1:T}^{t},\theta^{t})}{q(x_{1:T}^{*}|y_{1:T}^{*},\theta^{*})}\\
    &= \frac{p(x_{1:T}^{*}|y_{1:T},\theta^{*})}{p(x_{1:T}^{t}|y_{1:T},\theta^{t})}\frac{p(\theta^{*}|y_{1:T})}{p(\theta^{t}|y_{1:T})}\frac{q(\theta^{t}|\theta^{*})}{q(\theta^{*}|\theta^{t})}\frac{q(x_{1:T}^{t}|y_{1:T}^{t},\theta^{t})}{q(x_{1:T}^{*}|y_{1:T}^{*},\theta^{*})}\\
    &= \frac{p(\theta^{*}|y_{1:T})}{p(\theta^{t}|y_{1:T})}\frac{q(\theta^{t}|\theta^{*})}{q(\theta^{*}|\theta^{t})}\\
   & = \frac{p(y_{1:T}|\theta^{*}}{p(y_{1:T}|\theta^{t}}\frac{\theta^{*}}{\theta{t}}\frac{q(\theta^{t}|\theta^{*})}{q(\theta^{*}|\theta^{t})}
\end{align}
\end{document}

答案3

  • 从你的代码片段可以推断出你使用了unicode-mathXeLaTeX或者LuaLaTeX来打包并编译文档。
  • 错误是由 @Ulrike 在其评论中指出的。在下面的 MWE 中,缺少右括号的代码行,括号和右括号标记为<---
\documentclass{article}
\usepackage{amsmath}
\usepackage{polyglossia}
\usepackage{unicode-math}


\begin{document}
\begin{align}

相关内容