# Equation with sectioning numbering problem

I need special numbering for equations in my work, so I made it similar to figures numbering which egreg wrote here

This is my MWE:

\documentclass[12pt, a4paper, oneside, onecolumn]{article}
\usepackage{mathtools}
\renewcommand{\theequation}{%
\ifnum\value{subsection}=0
\thesection.\arabic{figure}%
\else
\ifnum\value{subsubsection}=0
\thesubsection.\arabic{figure}%
\else
\thesubsubsection.\arabic{figure}%
\fi
\fi
}
\begin{document}
\section{Section}
$$\begin{split} R' &= R/255 \\ G' &= G/255 \\ B' &= B/255 \end{split}$$

\subsection{Subsection}
$$\begin{split} C_{max} &= max(R', G', B') \\ C_{min} &= min(R', G', B') \\ \Delta &= C_{max} - C_{min} \end{split}$$

\end{document}


It gives me this type of numbering, which is good, but the number of equation is wrong:

If I use it in my document it looks like this:

The 2.1.2. part is fine, that's the number of my subsubsection, but the rest is wrong. It should be 2.1.2.1 and 2.1.2.2 Could you tell me what have I done wrong here?

• you want {equation} not {figure} in each case, you are incrementing the equation counter then printing the figure one, change to print the equation counter Sep 14, 2013 at 18:33

There are two separate issues with the code in your MWE:

• You need to affix \arabic{equation}, not \arabic{figure}, to the various redefinitions of \theequation. This has already been pointed out by David Carlisle. (This is why the first couple of equation numbers terminate in .0. My guess is that your document has two figure environments prior to the second batch of equations you show; it's the most straightforward explanation of why the final digit of both equation numbers is stuck at .2.)

\usepackage{chngcntr}

An off-topic comment: Don't typeset "max" and "min" in plain math-italic mode. Use \max and \min where they occur as math operators, and write C_{\textup{max}} and C_{\textup{min}} for the subscript instances. If you have a lot of those instances, you define some macros in the preamble, say \newcommand{\Cmax}{C_{\textup{max}}}, and use \Cmax throughout the document.