软件包 amsmath 错误:多个 \label

软件包 amsmath 错误:多个 \label

对于之前代码中的错误,深表抱歉。

有人能帮助对方程式中的 \overset 或 \underset 进行编号吗?

由于变量太多,我需要在方程中某些变量的上方/下方添加数字。方程很长。我考虑使用计数器自动对方程中的变量进行编号。我尝试了以下代码,但似乎 \overset 和 \underset 与方程的标签冲突。

我收到以下错误:

Package amsmath Error: Multiple \label's: label 'Eq1' will be lost. Y & = \overset{\dln{aaa}}{\boxed{a}}

有谁能帮我一下吗?非常感谢。代码在这里:

\documentclass{article}

\usepackage{amssymb}
\usepackage{amsmath}


\newcounter{rtaskno}
\DeclareRobustCommand{\dln}[1]{%
    \refstepcounter{rtaskno}%
    \thertaskno\label{#1}}

\begin{document}

Here is the equation:\\

\begin{equation}\label{Eq1} % I need the Eq. number
\begin{aligned} % I need the aligned equation
Y & = \overset{\dln{aaa}}{\boxed{a}} x_1  \\ % I need the aaa to be auto numbered
& + \underset{2}{\boxed{b}} x_2  % I need the bbb to be auto numbered
\end{aligned}
\end{equation}

Here is how to refer \dln{aaa}. % I need to refer the number indexed by aaa

\end{document}

这就是我要的: 在此处输入图片描述

答案1

在此处输入图片描述

\documentclass{article}



\usepackage{amssymb}
\usepackage{amsmath}

\makeatletter
\def\zzlabel#1{\ifmeasuring@\else\ltx@label{#1}\fi}
\makeatletter


\newcounter{rtaskno}
\DeclareRobustCommand{\dln}[1]{%
    \refstepcounter{rtaskno}%
    \thertaskno\zzlabel{#1}}

\begin{document}

Here is the equation:% never \\ at and of paragraph
\begin{equation}\label{Eq1} % I need the Eq. number
\begin{aligned} % I need the aligned equation
Y & = \overset{\dln{aaa}}{\boxed{a}} x_1  \\ % I need the aaa to be auto numbered
& + \underset{\dln{bbb}}{\boxed{b}} x_2  % I need the bbb to be auto numbered
\end{aligned}
\end{equation}

Here is how to refer aaa: \ref{aaa}. % I need to refer the number indexed by aaa

Here is how to refer bbb: \ref{bbb}. % I need to refer the number indexed by aaa

\end{document}

相关内容