4

I have several equations spanning multiple lines, using \begin{equation} \begin{aligned} to give each of them one equation number. For example:

\begin{equation}
\begin{aligned}
\forall &a. \\
  &a \in A \rightarrow \\
  &\ a \in B
\end{aligned}
\end{equation}

To help explanation, I would like to add line numbers to the equations. Surely, each of them would restart numbering from 1. For the above example, I would hope it always has line numbers from 1 to 3.

Searching on the site only finds results related to equation numbering, which is not what I'm asking for; the other type of results is about a package lineno which seems to number the whole document, and it has some issues with amsmath.

Is there a way to automatically number the lines?


Thanks @mickep for the example illustrating what I want to achieve:

Equation with line numbers

4
  • 1
    Where do you want the line numbers to appear?
    – frabjous
    Aug 6, 2022 at 23:27
  • 1
    Are you simply looking for the subequations environment?
    – Vincent
    Aug 6, 2022 at 23:34
  • 1
    I added one example of what I think is what you want. If it is not what you intended, please just revert my edit. Take it as a suggestion to include an image of what you want next time you ask a question. It gets so much easier for people to help (and not to waste time on guessing what you want).
    – mickep
    Aug 7, 2022 at 9:47
  • 1
    Thanks @mickep! That is indeed what I want.
    – renyuneyun
    Aug 7, 2022 at 16:50

1 Answer 1

1

As @Vincent has already suggested in a comment, the subequations machinery of the amsmath package fits your use case very well. In particular, sub-equations marked (2a), (2b), etc can be cross-referenced readily using the standard LaTeX \label-\ref (or \eqref) mechanism.

enter image description here

\documentclass{article} % or some other suitable document class
\usepackage{amsmath} % for aligned, subequations, and align environments
\setlength\textwidth{8cm} % just for this example
\begin{document}

\begin{equation}
\begin{aligned}
 a &= b+c+d \\
   &= e+f+g
\end{aligned}
\end{equation}

\begin{subequations}
\begin{align}
 a &= b+c+d \label{eq:abcd}\\
   &= e+f+g
\end{align}
\end{subequations}

As pointed out in equation \eqref{eq:abcd}, \dots

\end{document}

Addendum to address the OP's follow-up questions.

But can I still keep the equation number as a whole as well? For example, for the second equation, can it have both the equation number 2 and a list of sub-equation numbers for each line?

To cross-reference an entire group of subequations, add a \label instruction immediately after \begin{subsequations}. E.g., if you add \label{eq:group2} after \begin{subsequations} in the example above, you can create a cross-reference to the entire group of equations via \eqref{eq:group2}.

I really don't think it's necessary, or even advisable, to create an explicit (2) numeric label for the overall group of equations. If you are seriously concerned that your readers will be incapable of figuring out that equations 2a, 2b, etc are collectively members of a group of equations that share the number 2, then your readers are in seriously deep trouble in terms of basic reading comprehension -- and they will likely never read your paper to begin with...

And can I have numbers rather than letters as the line "number" (e.g. can I have "2-1" rather than "2a" in the example)

Yes. If you want this change to apply to all subequations environments in the document, I suggest you add the instructions

\usepackage{xpatch}  % for \xpatchcmd macro
\xpatchcmd{\subequations}{\alph{equation}}{-\arabic{equation}}{}{}

in the preamble, after loading amsmath.

2
  • 1
    Thanks for the example and explanation. It's not unacceptable to use separate equation numbers as line numbers. But can I still keep the equation number as a whole as well? For example, for the second equation, can it have both the equation number 2 and a list of sub-equation numbers for each line? And can I have numbers rather than letters as the line "number" (e.g. can I have "2-1" rather than "2a" in the example)?
    – renyuneyun
    Aug 7, 2022 at 16:49
  • @renyuneyun - The answer to both of your follow-up questions is "yes". Please see the addendum I just posted for more information.
    – Mico
    Aug 7, 2022 at 17:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .