[Tex/LaTex] Problem with cross referencing using gather environment

amsmathcross-referencingequations

I am using gather environment to write bunch of equations. When I try to cross-reference those equations, the equation number doesn't show up. Here is my code

\documentclass[12 pt]{article}
\usepackage{fullpage}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{subfigure}
\usepackage{float}
\usepackage{setspace}
\usepackage{longtable}
\usepackage{lscape}
\usepackage{color}
\usepackage{tabularx}
\usepackage{multirow}
\usepackage{caption}
\usepackage{array}
\makeatletter
\newcommand*{\compress}{\@minipagetrue}
\makeatother
\doublespacing

\begin{document}

\begin{gather}\label{eq:1}
    a=1  \nonumber \\
    b=1
\end{gather}
Equation \ref{eq:1}
\end{document}

The equation number is supposed to show up after "Equation" but its missing. What could be the problem? If I remove \nonumber then thing seems to work fine but I need \nonumber.

Best Answer

For this you need to use the gathered environment from amsmath and place the \label outside that environment. Another quick-and-dirty way to achieve this, without using amsmath, would be to use an array:

enter image description here

\documentclass{article}
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\begin{document}
\begin{equation}
  \begin{gathered}
    a = 1 \\ b = 2
  \end{gathered}\label{eq:1}
\end{equation}
Equation~\eqref{eq:1} and~\eqref{eq:2}.
\begin{equation}
  \begin{array}{c}
    a = 1 \\[\jot] b = 2
  \end{array} \label{eq:2}
\end{equation}
\end{document}

Also consider using \eqref instead of \ref for equations, since this is fully supported by amsmath to duplicate the behaviour of the equation number, even in other fonts.

Related Question