4

I am having problems using align. I would like my equations and text to all line up. The first equation is displayed fine, but the next few go off the side of the page. Here is my code:

\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} 

This code is giving me something like this: enter image description here

But I would like it all to stay within the page.

3
  • How exactly should they line up? It's not strange that you get that result, there are no alignment points (&) in the first line, so everything is placed in the first column. Commented May 10, 2016 at 5:44
  • That's a great point. I didn't realize that alignment points mattered between lines. I thought they only mattered within lines. Commented May 10, 2016 at 5:47
  • Of course they do. The whole point is to align for example = in consecutive lines. Commented May 10, 2016 at 5:48

3 Answers 3

5

The following may be what you're looking for:

enter image description here

\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} 

Assigning equation numbers to the explanatory lines may not be needed or desirable. If this hunch is correct, the following solution may be preferable.

enter image description here

\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} 
0
2

I propose this simple code, since there's nothing really to align in the equation, I use a gather environment, and tabularx and 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} 

enter image description here

1
  • @Mico: Done. Thank you for pointing it. I often copy the code from the screen, and my editor displays some commands as symbols symbols for better legibility. Commented May 10, 2016 at 15:35
0

I got it. Just splitting the align equations up works.

\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} 
1
  • 2
    This really isn't a recommended way of doing that, you get a lot of extra whitespace. Try with your original code, remove all the & and replace align with gather. Commented May 10, 2016 at 5:50

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.