How can I reset equation numbering in each subsection*?

I am a lyx user, and made a document using subsection*(unnumbered subsection). I want to reset equation numbering each subsection and tried several methods, but all of them did not work.

What I tried(I tried adding below in the document-setting-Preamble):

1.

\makeatletter
\makeatother

 \numberwithin{equation}{subsection}

\usepackage{chngcntr}
\counterwithin*{equation}{subsection}


How I want to show: without part number, section number, just (number) only. like below.

Usually the equation counter can be reset at each new subsection with \numberwithin, like in your second trial. However, this does not work when the subsection counter is not incremented.

Another simple method is to renew the usual \subsection command to reset the equation counter before calling the old command.

Here's a complete example of this method.

\documentclass{article}
\usepackage{amsmath}
\let\oldsubsection\subsection
\renewcommand{\subsection}{%
\setcounter{equation}{0}%
\oldsubsection%
}

\begin{document}

\section{A section}

\subsection*{A first subsection}

$$E = mc^2$$

\subsection*{A second subsection}

$$G_{\mu\nu} + \Lambda g_{\mu\nu} = \kappa T_{\mu\nu}$$

\end{document}

• I wanna reset the numbering. In your example, I want to put (1), instead of (2), in the second equation. Nov 9, 2020 at 3:06
• @user14261785 Wow indeed, I'm sorry. I guess I misread my own example! I'll modify my answer in a bit. Nov 9, 2020 at 3:31
• @user14261785 Done! Nov 9, 2020 at 3:54
• Thank you, you're so great! Nov 9, 2020 at 3:57