7
\documentclass{article}
\usepackage{mathtools}
\usepackage{eqparbox}
\newcommand\eqmathbox[2][M]{\eqmakebox[M#1]{$\scriptstyle#2$}}

\newcommand{\prodsincos}{\prod_{j\in A}
\sin\alpha_j \prod_{j\notin A} \cos\alpha_j}

\begin{document}

\begin{align}
\begin{split} \label{fn of a+b}
\cos(\alpha+\beta) & = \cos\alpha\cos\beta - \sin\alpha\sin\beta \\
\sin(\alpha+\beta) & = \sin\alpha\cos\beta + \cos\alpha\sin\beta
\end{split}
\end{align}

\begin{alignat}{2}
\begin{split}
\cos \sum_j \alpha_j
& = \sum_{k=0}^\infty (-1)^k
&& \sum_{|A|=2k}
\prodsincos \\
\sin \sum_j \alpha_j
& = \sum_{k=0}^\infty (-1)^k
&&\sum_{|A|=2k+1}
\prodsincos
\end{split}
\end{alignat}

\end{document}

The code above works fine if I omit \begin{split} and \end{split}. The purpose of split was to get just one equation number. With split, I get this error message:

! Extra alignment tab has been changed to \cr.
<template> }$\hfill \endtemplate

What should I do?

Andrew Swann
  • 95,762
  • Split only allows for a single alignment column, thus only one & per row. You're probably looking for alignedat – daleif Jun 06 '16 at 04:43
  • this is a good example of why equation should be used for "one-line" (or one equation number) displays rather that align and friends. – barbara beeton Jun 06 '16 at 13:55

2 Answers2

8

To have just one equation number it is reasonable to use equation as the outer environment. A split will provide a single alignment point, if you need more use alignedat, or aligned, instead. For the differences between aligned and alignedat, see https://tex.stackexchange.com/a/200844/15925; most notable is the default amount of spacing added by aligned.

Sample output

\documentclass{article}

\usepackage{mathtools}

\usepackage{eqparbox}
\newcommand\eqmathbox[2][M]{\eqmakebox[M#1]{$\scriptstyle#2$}}

\newcommand{\prodsincos}{\prod_{j\in A}
\sin\alpha_j \prod_{j\notin A} \cos\alpha_j}

\begin{document}

\begin{equation}
  \begin{split} \label{fn of a+b}
    \cos(\alpha+\beta) & = \cos\alpha\cos\beta - \sin\alpha\sin\beta \\
    \sin(\alpha+\beta) & = \sin\alpha\cos\beta + \cos\alpha\sin\beta
  \end{split}
\end{equation}

\begin{equation}
  \begin{aligned} \label{fn2 of a+b}
    \cos(\alpha+\beta) & = \cos\alpha\cos\beta - \sin\alpha\sin\beta \\
    \sin(\alpha+\beta) & = \sin\alpha\cos\beta + \cos\alpha\sin\beta
  \end{aligned}
\end{equation}

\begin{equation}
  \begin{alignedat}{2}
    \cos \sum_j \alpha_j
    & = \sum_{k=0}^\infty (-1)^k
    && \sum_{\eqmathbox{|A|=2k}}
    \prodsincos \\
    \sin \sum_j \alpha_j
    & = \sum_{k=0}^\infty (-1)^k
    &&\sum_{\eqmathbox{|A|=2k+1}}
    \prodsincos
  \end{alignedat}
\end{equation}

\begin{equation}
  \begin{aligned}
    z &= \sqrt{x^2 + y^2}&&\text{by Pythagoras}\\
    &= 5&&\text{inserting \( x=3 \), \( y=4 \)}
  \end{aligned}
\end{equation}

\end{document}
Andrew Swann
  • 95,762
  • 1
    both aligned and alignedat supports more than one alignment column, split only supports one. – daleif Jun 06 '16 at 06:33
  • @daleif Yes, I always forget that, but it is not mentioned in the AMS documentation. For other people reading this see e.g. http://tex.stackexchange.com/a/200844/15925. I'll update the answer – Andrew Swann Jun 06 '16 at 08:10
3

You can use aligned:

enter image description here

\documentclass{article}

\usepackage{mathtools}

\newcommand{\prodsincos}{\prod_{j\in A}\sin\alpha_j \prod_{j\notin A} \cos\alpha_j}

\begin{document}

\begin{equation}\label{fn of a+b}
  \begin{aligned}
    \cos(\alpha+\beta) &= \cos\alpha\cos\beta - \sin\alpha\sin\beta\\
    \sin(\alpha+\beta) &= \sin\alpha\cos\beta + \cos\alpha\sin\beta
  \end{aligned}
\end{equation}

\begin{equation}
  \begin{aligned}
    \cos \sum_j \alpha_j
    &= \sum_{k=0}^\infty (-1)^k \sum_{|A|=2k} \prodsincos\\
    \sin \sum_j \alpha_j
    &= \sum_{k=0}^\infty (-1)^k \sum_{|A|=2k+1} \prodsincos
  \end{aligned}
\end{equation}

\end{document}
user94293
  • 4,254