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)?
Asked
Active
Viewed 170 times
3
rrrrr
- 503
2 Answers
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
\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
5
Locally
Just put \def\theequation{\theparentequation.\arabic{equation}}% after \begin{subequations}.
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
Clara
- 6,012



subequationsenvironments, but not all, do I simply put the\patchcmd\subequations{\alph{equation}}{.\arabic{equation}}{}{}call in the desiredsubequationsenvironment? – rrrrr May 10 '23 at 01:59\subequationscommand has to be patched before executing\begin{subequations}. (Basically, upon entering thesubequationsenvironment, LaTeX executes\subequations*macro; upon leaving thesubequationsenvironment, LaTeX executes\endsubequations.) I'd therefore use something like\begingroup \patchcmd\subequations{\alph{equation}}{.\arabic{equation}}{}{} \begin{subequations} ... \end{subequations} \endgroupto localize the change to a particularsubequationsenvironment. – Mico May 10 '23 at 02:03