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?

David Carlisle
  • 757,742
Jellby
  • 3,323

5 Answers5

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.

egreg
  • 1,121,712
  • 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 '17 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 '17 at 18:42
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}
David Carlisle
  • 757,742
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}
Ian Thompson
  • 43,767
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.

cmhughes
  • 100,947
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.