我在使用时遇到问题align
。我希望我的方程式和文本全部对齐。第一个方程式显示正常,但接下来的几个方程式偏离了页面的一侧。这是我的代码:
\documentclass[12pt, letterpaper]{article}
\usepackage{amssymb, amsmath}
\usepackage[utf8]{inputenc}
\usepackage{setspace}
\setlength{\parskip}{1.2ex}
\setlength{\parindent}{2em}
\begin{document}
\begin{align}
P(p_{i}, \pi, \theta| data) \propto \prod_{i} P(data| p_{i}, n)\times P(p_{i}|\pi,\theta)\times P(\pi)\times P(\theta)\\
\text{where} & P(p_{i}, \pi, \theta| data) & \text{is the \textbf{posterior} distribution}\\
\text{where} & P(data| p_{i}, n) \sim Binomial(p, n=10^{6}) & \text{ is the \textbf{Likliehood}}\\
\text{where} & P(p_{i}|\pi,\theta) \sim Beta(\pi\theta, (1-\pi)\theta)\\
\text{where} & P(\pi) \sim Beta(1,1) & \text{ is the initial \textbf{prior} distribution}\\
\text{where} & P(\theta) \sim Uniform(10^{-3}, 10^{4}) & \text{ is the distribution used to draw samples of \textbf{precision} for the Beta distribution}
\end{align}
\end{document}
但我希望所有内容都保留在页面内。
答案1
以下内容可能就是您正在寻找的内容:
\documentclass[12pt, letterpaper]{article}
\usepackage{amssymb,mathtools}
\usepackage[utf8]{inputenc}
\usepackage{setspace}
\setlength{\parskip}{1.2ex}
\setlength{\parindent}{2em}
\begin{document}
\begin{align}
&P(p_{i}, \pi, \theta\mid \text{data}) \propto \prod_{i} P(\text{data}\mid p_{i}, n)\times P(p_{i}\mid \pi,\theta)\times P(\pi)\times P(\theta)\\
\shortintertext{where}
&P(p_{i}, \pi, \theta\mid\text{data}) \text{ is the \textbf{posterior} distribution}\\
&P(\text{data}\mid p_{i}, n) \sim \mathrm{Binomial}(p, n=10^{6}) \text{ is the \textbf{likelihood}}\\
&P(p_{i}\mid \pi,\theta) \sim \mathrm{Beta}(\pi\theta, (1-\pi)\theta)\\
&P(\pi) \sim \mathrm{Beta}(1,1) \text{ is the initial \textbf{prior} distribution}\\
&P(\theta) \sim \parbox[t]{0.7\textwidth}{$\mathrm{Uniform}(10^{-3}, 10^{4})$ is the distribution used to draw samples of \textbf{precision} for the Beta distribution}
\end{align}
\end{document}
为解释线分配方程编号可能没有必要或不合时宜。如果这个猜测是正确的,那么以下解决方案可能更可取。
\documentclass[12pt, letterpaper]{article}
\usepackage{amssymb,mathtools}
\usepackage[utf8]{inputenc}
\usepackage{setspace}
\setlength{\parskip}{1.2ex}
\setlength{\parindent}{2em}
\begin{document}
\begin{equation}
P(p_{i}, \pi, \theta\mid \text{data}) \propto \prod_{i} P(\text{data}\mid p_{i}, n)\times P(p_{i}\mid \pi,\theta)\times P(\pi)\times P(\theta)
\end{equation}
where
\begin{align*}
&P(p_{i}, \pi, \theta\mid\text{data}) \text{ is the \textbf{posterior} distribution}\\
&P(\text{data}\mid p_{i}, n) \sim \mathrm{Binomial}(p, n=10^{6}) \text{ is the \textbf{likelihood}}\\
&P(p_{i}\mid \pi,\theta) \sim \mathrm{Beta}(\pi\theta, (1-\pi)\theta)\\
&P(\pi) \sim \mathrm{Beta}(1,1) \text{ is the initial \textbf{prior} distribution}\\
&P(\theta) \sim \parbox[t]{0.7\textwidth}{$\mathrm{Uniform}(10^{-3}, 10^{4})$ is the distribution used to draw samples of \textbf{precision} for the Beta distribution}
\end{align*}
\end{document}
答案2
我提出这个简单的代码,因为等式中没有什么真正需要对齐,所以我使用环境gather
,和tabularx
和enumitem
:
\documentclass[12pt, letterpaper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amssymb,mathtools}
\usepackage{tabularx, enumitem}
\begin{document}
\begin{gather}
P(p_{i}, \pi, \theta \mid \text{data}) \propto \prod _{i} P(\mathrm{data}\mid p_{i}, n) \times P(p_{i}\mid \pi,\theta ) \times P(\pi ) \times P(\theta )\\
\begin{tabularx}{\linewidth}{@{}l@{\quad}|X@{\qquad}}
where & \begin{description}[itemsep = 0pt,topsep = 0pt, before={\leavevmode\vspace{-\dimexpr\baselineskip + \topsep\relax}}, after=\vspace{-\baselineskip}]%
\item[$ P(p_{i}, \pi, \theta\mid \mathrm{data})$] is the \textbf{posterior} distribution, %
\item[$ P(\mathrm{data}\mid p_{i}, n) \sim \mathrm{Binomial}(p, n=10^{6}) $] is the \textbf{likelihood}, %
\item[$ P(p_{i}\mid \pi, \theta) \sim \mathrm{Beta}(\pi\theta, (1- \pi)\theta) $,] %
\item[$ P(\pi) \sim \mathrm{Beta}(1,1) $] is the initial \textbf{prior} distribution, %
\item[$ P(\theta) \sim \mathrm{Uniform}(10^{-3}, 10^{4})$] is the distribution used to draw samples of \textbf{precision} for the Beta distribution.%
\end{description}
\end{tabularx}\notag
\end{gather}
\end{document}
答案3
我明白了。只要把align
方程式分开就可以了。
\begin{equation}
P(p_{i}, \pi, \theta| data) \propto \prod_{i} P(data| p_{i}, n)*P(p_{i}|\pi,\theta)*P(\pi)*P(\theta)
\end{equation}
\begin{align}
\text{where} & P(p_{i}, \pi, \theta| data) & \text{is the \textbf{posterior} distribution}
\end{align}
\begin{align}
\text{where} & P(data| p_{i}, n) \sim Binomial(p, n=10^{6}) & \text{ is the \textbf{Likliehood}}
\end{align}
\begin{align}
\text{where} & P(p_{i}|\pi,\theta) \sim Beta(\pi\theta, (1-\pi)\theta)
\end{align}
\begin{align}
\text{where} & P(\pi) \sim Beta(1,1) & \text{ is the initial \textbf{prior} distribution}
\end{align}
\begin{align}
\text{where} & P(\theta) \sim Uniform(10^{-3}, 10^{4}) & \text{ is the distribution used to draw samples of \textbf{precision} for the Beta distribution}
\end{align}