2

To be specific, my problem is that I want to label the equations of a subsection (e.g 2.1) by

(2.1(a), 2.1(b), ...)

I know that if I use the \numberwithin{equation}{subsection} command, but in that case I get 2.1.1 instead of my desired one. I am not very expert in LaTeX, but is there any way so that I could get my desired labeling automatically. Because manually it can be done I think by the use of \tag command.

Thank you.

  • Welcome to TeX.SE. Should the equation "numbers" still be surrounded by parentheses, i.e., displayed as (2.1(a)), or should the outer parentheses be omitted, so that the equation number would be displayed as 2.1(a)? Please advise. – Mico Apr 28 '18 at 8:38
2

I'm assuming that since the new form of the equation "number" contains a pair of parentheses, equation numbers shouldn't be displayed encased in an additional pair of parentheses. Please advise if this assumption is incorrect.

Instead of using the \numberwithin approach, I suggest you proceed as shown in the following example.

enter image description here

\documentclass{article}
\usepackage{amsmath} 
\renewcommand\theequation{\thesubsection(\alph{equation})}
\makeatletter
\def\tagform@#1{\maketag@@@{\ignorespaces#1\unskip\@@italiccorr}} % no parentheses
\@addtoreset{equation}{subsection}
\makeatother
\begin{document}

\setcounter{section}{2}    % just for this example
\setcounter{subsection}{1} % just for this example
\begin{equation}\label{eq:112} 1+1=2 \end{equation}

\refstepcounter{subsection}
\addtocounter{equation}{3}
\begin{equation} 0+0=0 \end{equation}
A cross-reference to equation~\eqref{eq:112}.
\end{document}
  • I think your assumption that there is no need of extra parentheses is justified. Thanks for your answer and time. Actually I am writing my project work in latex and in case if my senior wants an extra parentheses ( which may happen as he is a little weird), will you please give the code in addition for the extra parentheses ? Thank you@Mico. – hiren_garai Apr 28 '18 at 10:03
  • 1
    @HirenGarai - You're most welcome. If you do end up needing the outer parentheses, simply omit the instruction \def\tagform@#1{...}. – Mico Apr 28 '18 at 10:31
  • Thanks once again.. I have some queries, if you don't mind will you tell me whether this can be done by the \numberwithin approach as you suggested your method in stead of that approach ? @Mico – hiren_garai Apr 28 '18 at 13:33
  • 1
    @HirenGarai - As you've probably noticed, \numberwithin{}{} inserts a "dot" between the subsection number and the "inner" (lowercase letter) equation number -- something that you don't seem to want. In order to avoid getting the dot, it would be necessary to hack the \numberwithin macro. And it would still be necessary to provide instructions to (a) get rid of the "outer" parentheses and (b) change the inner numbering style to lowercase letters. All in all, it seemed to me that the solution I posted was a lot simpler... – Mico Apr 28 '18 at 13:48
  • I got it. Thank you @Mico. Actually my problem is that as I am not quite aware of all the latex commands or "hacks", so I have stuck in some places on your solution thinking what's the need(work) of this command. – hiren_garai Apr 28 '18 at 13:51
1

Another solution, based on the \newtagform command from mathtools. We can revert to the default tag form (or any other indeed) with \usetagform{default}:

\documentclass{article}
\usepackage{mathtools}

\makeatletter
\newtagform{alphanum}[\thesubsection\alph{equation}\@gobble]{(}{)}
\makeatother

\begin{document}

\setcounter{section}{2} % just for this example
\setcounter{subsection}{1} % just for this example

\usetagform{alphanum}
\begin{equation}\label{eq:112} 1+1=2 \end{equation}

\refstepcounter{subsection}
\addtocounter{equation}{3}
\begin{equation} 0+0=0 \end{equation}
A cross-reference to equation~\eqref{eq:112}.

\section{Another section}

\usetagform{default}

Another equation with the usual numbering:

\begin{equation}\label{eq:112} 2\times3=6 \end{equation}

\end{document} 

enter image description here

  • Thank you for your time and answer, @Bernard. I have a little problem which is slightly different from my question, while writing an equation in a subsubsection 2.1.1 which is under the subsection 2.1(which is under the section 2) the equation get labelled as 2.1.1.2 with the numberwithin command, why this happens ? As the equation should have labelled as 2.1.1.1 – hiren_garai Apr 28 '18 at 10:07
  • I tested, from what I understand, and have no such problem. Could post a small example? – Bernard Apr 28 '18 at 10:31
  • Assuming that the "inner" equation numbers (a, b, ...) should be reset each time the subsection counter is stepped, I think you also need \@addtoreset{equation}{subsection}. At least in my view, the second equation in your example should be numbered 2.2d, not 2.2e... – Mico Apr 28 '18 at 10:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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