# reset \subsection between \section*

For some reasons, I want to use \section* in my document, but since I also use \subsection, they don't get refreshed. To be more specific:

\section*{AA}
\subsection{aa}
\subsection{aaa}
\subsection{aaaa}
\subsection{aaaaa}
\section*{BB}
\subsection{bb}
\subsection{bbb}
\subsection{bbbb}
\subsection{bbbb}


will produce this:

How do I make sure that \subsection get restarted between \section*? The subsections under AA and BB should start from 1.

EDIT: The section prefix should preferably be gone.

• Try \setcounter{subsection}{0} after \section*{BB}. – marmot Sep 12 '18 at 20:38
• Where does the 2 comes from? – Ulrike Fischer Sep 12 '18 at 20:43
• @UlrikeFischer Just quickly used Overleaf to create the case... probably from previous sections... – Quang Thinh Ha Sep 12 '18 at 20:47
• But in your document will it be there too or do you want to number the subsection without this prefix? – Ulrike Fischer Sep 12 '18 at 20:47
• Is every section specified with \section*? – egreg Sep 12 '18 at 20:53

If all sections are unnumbered, this seems to be the simplest solution: remove the number from the section title.

\documentclass{article}

\makeatletter
\renewcommand{\@seccntformat}[1]{%
\ifcsname specialformat#1\endcsname
\csname specialformat#1\endcsname
\else
\fi
}
\makeatother

\newcommand{\specialformatsection}{}
\renewcommand{\thesubsection}{\arabic{subsection}}

\begin{document}

\section{AA}
\subsection{aa}
\subsection{aaa}
\subsection{aaaa}
\subsection{aaaaa}
\section{BB}
\subsection{bb}
\subsection{bbb}
\subsection{bbbb}
\subsection{bbbb}

\end{document}


Note that you have to use \section, rather than \section*.

You may use \setcounter{section} or \setcounter{subsection}, depending on your need.

\section*{AA}
\setcounter{section}{1}
\subsection{aa}
\subsection{aaa}
\subsection{aaaa}
\subsection{aaaaa}
\section*{BB}
\setcounter{section}{2}
\subsection{bb}
\subsection{bbb}
\subsection{bbbb}
\subsection{bbbb}