11

First of all, I'm not sure these environments are supposed to be nested, but the fact is the alignment comes out exactly how I wanted, and no errors are issued.

\documentclass[a5paper]{article}
\usepackage{amsmath}

\begin{document}

\begin{gather}
\begin{align}
a &= b + c \notag \\
%\label{important}
b - a &= -c \\
c - a &= -b
\end{align} \\
a - (b-a) - (c-a) = 2a
\end{gather}

\end{document}

enter image description here

The problem appears when I uncomment the \label, then compilation is interrupted with:

! Package amsmath Error: Multiple \label's: label 'important' will be lost.

The result is still OK, and I wouldn't mind too much if I didn't have to press enter every time I compile...

I could bypass amsmath's redefinition of \label as shown here, but is there another possible fix? Or am I doing something fundamentally wrong?

5 Answers 5

5

clearly this is a bug, and will be investigated as such.

but here's another horrible hack that merely gives the nasty warning that

LaTeX Warning: Label `important' multiply defined.

at least you wouldn't have to press enter every time ...

\documentclass[a5paper]{article}
\usepackage{amsmath}
\begin{document}
\begin{gather}
\begin{align}
a &= b + c \tag*{} \\
b - a &= -c
\label{important} \\
c - a &= -b
\end{align}\\
a - (b-a) - (c-a) = 2a
\end{gather}
some text with an xref: \eqref{important}
\end{document}
8

Using align inside gather is officially supported (see p. 23 of amsldoc.pdf, the end of section 10.2). However, using \label inside the inner align is buggy: if \notag is used, then the error is raised, if \notag is not used, a label in the second line is duplicated.

A horrible hack is to disable the error generation:

\makeatletter
\def\label@in@display{\gdef\df@label}
\makeatother

This of course will suppress the error also when it's legitimately raised, so use with care.

2
  • For me this horrible hack is the only thing that worked, using \tag*{} instead of \notag did not change anything in the generated errors. I use tETA2 style from Taylor & Francis, not article - maybe that is the reason.
    – peschü
    Mar 13, 2017 at 18:35
  • @peschü Impossible to say without seeing the style, but I'm not surprised that an in-house style has compatibility problems.
    – egreg
    Mar 13, 2017 at 18:42
1

The problem is with your \notag command, which instructs amsmath not to put a tag (in this case, a number) by the equation- hence, labelling it doesn't make any sense which is why you get the error.

If you want to \label that first equation, you'll need to remove the \notag from the first line. If you don't want to \label it, then the \notag is fine.

4
  • \notag is in the first line; the \label is in the second line. Jun 20, 2012 at 16:18
  • @IanThompson the \label wants to apply itself to the most recent <thing> which in this case is the first line. the \label works on the most recent thing, not on the next thing
    – cmhughes
    Jun 20, 2012 at 16:27
  • Try it for yourself with a simple example. Jun 20, 2012 at 16:31
  • @IanThompson already have. perhaps I have misunderstood the issue
    – cmhughes
    Jun 20, 2012 at 16:57
1

As @egreg points out, you can run into trouble if you nest the align environment in this way (despite the fact that it is supported). There is a variant called aligned that works inside other display math environments but this doesn't number the individual equations.

In your case I would be inclined to simplify matters by putting the last equation in its own environment, reducing the spacing between this and the align environment, and not using gather at all.

\documentclass[a5paper]{article}
\usepackage{amsmath}
\begin{document}
\bgroup %Grouping restores \belowdisplayskip after use
\setlength\belowdisplayskip\jot
\begin{align}
a &= b + c \notag \\    
\label{important}
b - a &= -c \\
c - a &= -b
\end{align}
\begin{equation}
a - (b-a) - (c-a) = 2a
\end{equation}
\egroup
\end{document}
4
  • 1
    But aligned does not give a number for each equation, it treats the whole block as a single equation instead (which is useful in other cases).
    – Jellby
    Jun 20, 2012 at 15:53
  • @Jellby --- I have edited my answer. Jun 20, 2012 at 16:18
  • 1
    At the end of section 10.2 of the documentation it's explicitly mentioned that align can be used inside gather.
    – egreg
    Jun 20, 2012 at 16:28
  • @egreg --- Right as always! I'll edit my answer later. Jun 20, 2012 at 16:34
0

Although it does not seem to be your problem here, this bug can also occur because of two \notag commands in the same line. Putting the \notag twice in the same line is useless and may seem innocuous, but it generates the aforementioned bug.

You must log in to answer this question.

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