3

I understand how to align multiple equations, but how can I do this if I want to also have text over the equalities. For example:

enter image description here

It bugs me that the equal signs are no longer aligned. Here is my LaTeX:

$$
\begin{align}
p(\textbf{x} \mid \mathcal{D}, \alpha)
&= \int p(\textbf{x} \mid \boldsymbol{\theta}) p(\boldsymbol{\theta} \mid \mathcal{D}, \alpha) \text{d} \boldsymbol{\theta}
\\
&\stackrel{\text{Eq 4}}{=} \int p(\textbf{x} \mid \boldsymbol{\theta}) p(\boldsymbol{\theta} \mid \alpha') \text{d} \boldsymbol{\theta}
\\
&= p(\textbf{x} \mid \alpha'). \tag{5}
\end{align}
$$

Is there a solution to this?

3
  • Off-topic: Encasing an align environment inside $$ ... $$ cannot possibly work correctly -- at least not as a LaTeX document. Please be more precise about you actually do.
    – Mico
    Apr 16, 2019 at 18:47
  • Fair point. I'm technically using MathJax, which requires this to work, but I should have edited it for the post.
    – jds
    Apr 16, 2019 at 20:34
  • MathJax (used on this site) works with align without $$ $$.
    – Bernard
    Apr 16, 2019 at 20:39

2 Answers 2

4

Here I use \mathclap to insure that the overstack takes up zero horizontal space.

Also, change the \textbf instances to \mathbf (thanks, Mico).

Finally, ditch the $$ delimiters.

\documentclass{article}
\usepackage{mathtools}
\begin{document}

\begin{align}
p(\mathbf{x} \mid \mathcal{D}, \alpha)
&= \int p(\mathbf{x} \mid \boldsymbol{\theta}) p(\boldsymbol{\theta} \mid \mathcal{D}, \alpha) \text{d} \boldsymbol{\theta}
\\
&\stackrel{\mathclap{\text{Eq 4}}}{=} \int p(\mathbf{x} \mid \boldsymbol{\theta}) p(\boldsymbol{\theta} \mid \alpha') \text{d} \boldsymbol{\theta}
\\
&= p(\mathbf{x} \mid \alpha'). \tag{5}
\end{align}


\end{document}

enter image description here

1
1

A simple \makebox[0pt]{...} will solve the probl.

Unrelated: do not nest align inside $$ ... $$ – and don't use the plain TeX construct ˆˆ ... $$ as it will yield incorrect spacing in LaTeX.

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\begin{align}
p(\textbf{x} \mid \mathcal{D}, \alpha)
&= \int p(\textbf{x} \mid \boldsymbol{\theta}) p(\boldsymbol{\theta} \mid \mathcal{D}, \alpha) \text{d} \boldsymbol{\theta}
\\
&\stackrel{\text{\makebox[0pt]{Eq 4}}}{=} \int p(\textbf{x} \mid \boldsymbol{\theta}) p(\boldsymbol{\theta} \mid \alpha') \text{d} \boldsymbol{\theta}
\\
&= p(\textbf{x} \mid \alpha'). \tag{5}
\end{align}

\end{document} 

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .