我有一段代码:
\begin{align*}
P(\omega_{k}|x) \approx \hat{y_k}(x) = \frac{exp(w^{T}_{k}x^')}{\sum^{q}_{j=1}exp(w^{T}_{j}x^')}
\\
where \quad x^' = [1, x_1, x_2,...,x_p]^T\quad\\
with \quad 0 \leq \hat{y_k}(x) \leq 1 \quad and \quad \sum^{q}_{k=1} \hat{y_k}(x) = 1
\end{align*}
这一直向我发送以下错误信息:
“!缺少 { 插入。^ l.295 \end{align*} 这里必须有一个左括号,所以我插入了一个。您可能需要删除和/或插入一些更正,以便我尽快找到匹配的右括号。(如果您对这一切感到困惑,请尝试现在输入“I}”。)”
我不知道该如何修复这个问题,因为我是 LaTeX 的新用户...有人能帮我吗?谢谢
答案1
好的,@Johannes_B 已经给了你一些建议。同时,我正在尝试整理你的代码:看看我是否猜对了你的意图。
% My standard header for TeX.SX answers:
\documentclass[a4paper]{article} % To avoid confusion, let us explicitly
% declare the paper format.
\usepackage[T1]{fontenc} % Not always necessary, but recommended.
\usepackage[ascii]{inputenc} % Just to check that the source is still pure,
% 7-bit-clean ASCII when you execute it, as it
% was when I wrote it.
% End of standard header. What follows pertains to the problem at hand.
\usepackage{mathtools}
\begin{document}
Text before.
\begin{gather*}
P(\omega_{k}|x) \approx \widehat{y_k}(x)
= \frac{\exp(w^{T}_{k}x')}{\sum^{q}_{j=1}\exp(w^{T}_{j}x')} \\[\jot]
\text{where} \quad x' = [1, x_1, x_2,\dots,x_p]^T \\
\text{with} \quad 0 \leq \widehat{y_k}(x) \leq 1 \quad
\text{and} \quad \sum^{q}_{k=1} \widehat{y_k}(x) = 1
\end{gather*}
Text after.
\end{document}
无论如何,我会使用不同的方法,在另一个等式中分离“哪里”后面的部分。
附录: 另一种可能性是使用split
环境。还请注意,通过命令引入了更高级别的抽象\innerprod
。
% My standard header for TeX.SX answers:
\documentclass[a4paper]{article} % To avoid confusion, let us explicitly
% declare the paper format.
\usepackage[T1]{fontenc} % Not always necessary, but recommended.
\usepackage[ascii]{inputenc} % Just to check that the source is still pure,
% 7-bit-clean ASCII when you execute it, as it
% was when I wrote it.
% End of standard header. What follows pertains to the problem at hand.
\usepackage{mathtools}
\DeclarePairedDelimiterX{\innerprod}[2]{(}{)}{%
#1\nonscript\medspace\delimsize\vert\nonscript\medspace\mathopen{}#2%
}
\begin{document}
Text before.
\begin{gather*}
\begin{split}
P\innerprod{\omega_{k}}{x} \approx \widehat{y_k}(x)
= \frac{\exp(w^{T}_{k}x')}{\sum^{q}_{j=1}\exp(w^{T}_{j}x')}
\qquad
&\text{where} \quad x' = [1, x_1, x_2,\dots,x_p]^T \\
&\text{with} \quad 0 \leq \widehat{y_k}(x) \leq 1 \\
&\text{and} \quad \sum^{q}_{k=1} \widehat{y_k}(x) = 1
\end{split}
\end{gather*}
Text after.
A few examples of the use of \verb|\innerprod|:
\begin{align*}
(a\mid b) &&
\innerprod{a}{b} &&
\innerprod[\Bigg]{a}{b} &&
\innerprod*{\frac{a}{b}}{\frac{c}{d}}
\end{align*}
\end{document}
答案2
我提出以下解决方案之一,其alignat
环境如下:
\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{mathtools}
\begin{document}
\begin{alignat*}{2}
P(\omega_{k}|x) & \approx \widehat{y_k}(x) & & = \frac{\exp(w^{T}_{k}x')}{\sum^{q}_{j=1}\exp(w^{T}_{j}x')}
\\[1ex]
& \text{where} & & \, x' = [1, x₁, x₂,...,x_p]^T \\[-1ex]
& \text{with} & & \, 0 \leq \widehat{y_k}(x) \leq 1 \quad \text{and} \quad \sum^{q}_{k=1} \widehat{y_k}(x) = 1
\end{alignat*}
\vskip1cm
\begin{alignat*}{2}
& & & P(\omega_{k}|x) \approx \widehat{y_k}(x) = \frac{\exp(w^{T}_{k}x')}{\sum^{q}_{j=1}\exp(w^{T}_{j}x')}
\\[1ex]
& \text{where}\quad & & x' = [1, x₁, x₂,...,x_p]^T \\[-1ex]
& \text{with} & & 0 \leq \widehat{y_k}(x) \leq 1 \quad \text{and} \quad \sum^{q}_{k=1} \widehat{y_k}(x) = 1
\end{alignat*}
\end{document}