在 alignat 中使用 split 时出现错误消息

在 alignat 中使用 split 时出现错误消息
\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}

\begin{split}如果我省略和,上面的代码可以正常工作\end{split}。的目的split是只获取一个方程编号。使用时split,我收到此错误消息:

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

我应该怎么办?

答案1

如果只有一个方程编号,则使用equation作为外部环境是合理的。Asplit将提供单个对齐点,如果您需要更多对齐点alignedat,请使用 或。对于和aligned之间的差异alignedalignedat,请参阅https://tex.stackexchange.com/a/200844/15925;最值得注意的是 添加的默认间距量aligned

示例输出

\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}

答案2

您可以使用aligned

在此处输入图片描述

\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}

相关内容