Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
    
So what do you want numbered? a=1, b=1, the whole thing, or none of it? Since you're referencing something, it can't be one of the former three... –  Werner Mar 11 '13 at 5:46
    
I want to reference all the equations within gather by one number which is same as the number for b=1 –  John Smith Mar 11 '13 at 5:54
    
Please always try and post minimal working examples - you include a lot of packages that are unrelated to your problem. –  Hendrik Vogt Mar 11 '13 at 10:53

2 Answers 2

up vote 2 down vote accepted

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.

share|improve this answer
    
Thanks this works perfectly. But the weird thing is the code that I provided above, I used it sometime before and it worked well. In any case, your solution is exactly what I wanted. –  John Smith Mar 11 '13 at 6:18

If you want to reference several equations by one number, then you can use gathered as Werner suggests, but I'd rather recommend the aligned environment in this case:

\documentclass[12pt]{article}
\usepackage{amsmath}
\begin{document}
\begin{equation}\label{eq:1}
  \begin{aligned}
    a &= 1 \\
    b &= 1
  \end{aligned}
\end{equation}
Equation~\eqref{eq:1}
\end{document}

output

The advantage of aligned is that you can use alignment tabs & to align the equals signs (which by coincidence is not necessary in your case). Note that you should use \eqref and not \ref for referencing the equation. Moreover, it's best to always use a tie ~ between the word "equation" and the \eqref so that you won't have a line break inbetween. (Obviously this can't happen here since we're at the beginning of a line, but just make it a habit.)


If you're wondering why you're code worked before, then my best guess is that you had the \nonumber \\ switched: with \\ \nonumber it works, more or less, since then the first equation has the label and the second one has no number:

output

\documentclass[12pt]{article}
\usepackage{amsmath}
\begin{document}
\begin{gather}\label{eq:1}
    a=1 \\ \nonumber 
    b=1
\end{gather}
Equation~\eqref{eq:1}
\end{document}
share|improve this answer
1  
I'd prefer the aligned environment to split, in this case; no substantial difference, but it makes intentions clearer: it's not a single equation split across lines, but two aligned equations (that we want to consider as a block nonetheless). –  egreg Mar 11 '13 at 10:54
    
I would also prefer aligned. Logically split is for dividing up one equation over several lines and aligning the result, aligned is for a group of equations. –  Andrew Swann Mar 11 '13 at 12:46
    
@Andrew: Thanks for insisting, egreg and you are so right! Edited accordingly. –  Hendrik Vogt Mar 11 '13 at 14:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.