1

Sorry about the previous errors in the code.

Could any one help with the numbering in the \overset or \underset in equations?

I need to add number above/below certain variables in the equations because I have so many variables. And the equations are very long. I consider to use the counter to auto-number the variables in equations. I tried the following code, but it seems that the \overset and \underset conflicts with the label of equation.

I got the following errors:

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

Does anyone please help me with it. Thanks a lot. The code is here:

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

This is what I want: enter image description here

  • 3
    Please consider cleaning up your previous question before asking a new one. – marmot Jan 25 at 23:19
  • 4
    As I told you in your other question: You can't have more than one label in an equation environment -- the \dln macro is logically wrong – Christian Hupfer Jan 25 at 23:27
  • Thank you. I deleted the previous post. I have a large number of coefficients/variables such as "a", "b", in the equations which I need to label. I can directly number them in the \overset or \underset. But if I insert a new number at the beginning, I have to change all the numbers affected. So, I hope to label the coefficients/variables using refstepcounter and refer them in the text through \dln{aaa}. – Yuan Jan 25 at 23:29
  • Thank you Christian. Is there any other way to deal with it? Or, I have to use \underset{1}{\boxed{a}} directly? – Yuan Jan 25 at 23:30
  • How about \begin{equation}\label{Eq1} \begin{aligned} Y & = \overset{\ref{Eq1}}{\boxed{a}} x_1 \\ & + \underset{\the\numexpr\theequation+1}{\boxed{b}} x_2 \end{aligned} \end{equation} ? – marmot Jan 25 at 23:46
1

enter image description here

\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}
  • Thank you so much David for solving my problem. It works very well. Thank you marmot, Christian, Werner, and Circumscribe. I really appreciate your discussion and suggestions. – Yuan Jan 27 at 19:28

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.