3

Similar to this question, how can I get the subequations environment to give me number.number style labels, e.g., labels like 1.1 and 1.2? How can I do so locally (i.e., not for the entire document)?

rrrrr
  • 503

2 Answers2

6

(edited answer to address OP's follow-up request)

You could use the command \patchcmd, which is provided by the etoolbox package, to "patch" the \subequations macro of the amsmath package:

\patchcmd\subequations{\alph{equation}}{.\arabic{equation}}{}{}

Put this command in the preamble to make the change global. If you want to keep the change local to a particular instance of a subequations environment, I suggest you enclose the patching command shown above and the subequations environment of interest in a TeX group, e.g., via

\begingroup
\patchcmd\subequations{\alph{equation}}{.\arabic{equation}}{}{}
\begin{subequations}
...
\end{subequations}
\endgroup

enter image description here

\documentclass{article}
\usepackage{amsmath}   % for 'subequations' environment
\usepackage{etoolbox}  % for '\patchcmd' macro
% the scope of the following instruction is *global*
\patchcmd\subequations{\alph{equation}}{.\arabic{equation}}{}{}

\begin{document}

\begin{subequations} \begin{gather} a+b=c \ d+e=f \end{gather} \end{subequations}

\end{document}

Mico
  • 506,678
  • great! If I want to only do this for some subequations environments, but not all, do I simply put the \patchcmd\subequations{\alph{equation}}{.\arabic{equation}}{}{} call in the desired subequations environment? – rrrrr May 10 '23 at 01:59
  • 1
    @rrrrr - The \subequations command has to be patched before executing \begin{subequations}. (Basically, upon entering the subequations environment, LaTeX executes \subequations *macro; upon leaving the subequations environment, LaTeX executes \endsubequations.) I'd therefore use something like \begingroup \patchcmd\subequations{\alph{equation}}{.\arabic{equation}}{}{} \begin{subequations} ... \end{subequations} \endgroup to localize the change to a particular subequations environment. – Mico May 10 '23 at 02:03
  • 1
    Great! WOuld you mind putting this in your answer? I've modified the question for future people in case they would like the option of doing local changes – rrrrr May 10 '23 at 02:13
  • 1
    @rrrrr - Please see the edit I've applied. – Mico May 10 '23 at 02:19
5

Locally

Just put \def\theequation{\theparentequation.\arabic{equation}}% after \begin{subequations}.

enter image description here

Globally

Put the code below after \usepackage{amsmath}.

\makeatletter
\renewenvironment{subequations}{%
  \refstepcounter{equation}%
  \protected@edef\theparentequation{\theequation}%
  \setcounter{parentequation}{\value{equation}}%
  \setcounter{equation}{0}%
  % \def\theequation{\theparentequation\alph{equation}}%
  \def\theequation{\theparentequation.\arabic{equation}}%
  \ignorespaces
}{%
  \setcounter{equation}{\value{parentequation}}%
  \ignorespacesafterend
}
\makeatother

enter image description here

Clara
  • 6,012