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:

enter image description here

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.

  • 3
    Try \setcounter{subsection}{0} after \section*{BB}. – marmot Sep 12 at 20:38
  • 1
    Where does the 2 comes from? – Ulrike Fischer Sep 12 at 20:43
  • @UlrikeFischer Just quickly used Overleaf to create the case... probably from previous sections... – Quang Thinh Ha Sep 12 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 at 20:47
  • 3
    Is every section specified with \section*? – egreg Sep 12 at 20:53
up vote 3 down vote accepted

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
    \csname the#1\endcsname\quad % default
  \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}

enter image description here

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}

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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