Referencing within an align

The following LaTeX document:

\begin{align*}
p{(A,RM,OL,O,LC)}   &=p(A)\;p(RM\mid A)\;p(OL\mid A,RM)\;p(O \mid A, RM, OL)    \\ &
\; \; \; \;p(LC\mid A, RM, OL,O) \label{eq:JPExample}
\end{align*}


does not display the reference \ref{eq:JPExample}. Why?

• Welcome to TeX.SX! A tip: If you indent lines by 4 spaces, they'll be marked as a code sample. You can also highlight the code and click the "code" button (with "{}" on it). – DG' Jan 26 '15 at 9:03
• Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. – mvkorpel Jan 26 '15 at 9:12
• You are trying to refer to an equation that has no number. It makes no sense. Change align* to align then it works. – user11232 Jan 26 '15 at 9:16
• ok. :) i am pretty new in latex :P but thanks for editing ;) – Rosa Jan 26 '15 at 13:28

Your alignment is not good. Here is how I would do it:

\documentclass{article}

\usepackage{amsmath}

\begin{document}

\begin{align}
p(A,RM,OL,O,LC)
={}& p(A) \cdot p(RM \mid A) \cdot p(OL \mid A,RM) \nonumber\\
&  \cdot p(O \mid A,RM,OL) \cdot p(LC \mid A,RM,OL,O). \label{eq:JPExample}
\end{align}
Here is equation~\eqref{eq:JPExample}.

\end{document}


or

\documentclass{article}

\usepackage{amsmath}

\begin{document}

$$\begin{split} p(A,RM,OL,O,LC) ={}& p(A) \cdot p(RM \mid A) \cdot p(OL \mid A,RM) \\ & \cdot p(O \mid A,RM,OL) \cdot p(LC \mid A,RM,OL,O). \label{eq:JPExample} \end{split}$$
Here is equation~\eqref{eq:JPExample}.

\end{document}


Notice the difference in the tag placement between the two approaches.

Also, I've

• removed the redundant brackets in p{(...)},
• put multiplications signs between each factor,
• moved one of the factor from the first line to the latter.
• you don't need gather; in this context, equation would be better. (aligned would also work as an alternative to split.) – barbara beeton Jan 26 '15 at 14:14

You can only reference equations which also have a number. Since you are using the align* environment, your equation does not have a number and hence cannot be referenced. In the align environment (without the *) they get a number and can be referenced.

Since you have multiple lines and probably only want one of these lines to have a number and to be referenced, you can use the \nonumber command from the amsmath package to prevent those lines from getting a number.

In the example below, the first equation is assigned numbering "(1)" and can be referenced. The second equation is not assigned any number and cannot be referenced.

\documentclass[a4paper,11pt]{report}
\usepackage{amsmath}  %align environment and equations withount unmbering

\begin{document}
\begin{align}
E & = m \cdot c^2
\label{eq:einstein}
\\
c^2 & = a^2 + b^2
\nonumber
\end{align}
This is a reference to equation \eqref{eq:einstein}.
%This is a reference to equation (1).
\end{document}


Note: The \eqref{...} command produces references enclosed in brackets as "equation (1)" compared to "equation 1" using the \ref{...} command.