Customise numbering in order to subdivide a single section into two parts

articlenumberingsectioning

I have an article class document. I am trying to divide a "section" into two parts such that a letter is added to the section number for the different parts. By "dividing" I mean visually, programming-wise I guess it is just customising the numbering. My aim is to have sections numbered in the following way:

1 Some Section

1.1 Some Subsection

2A Some Section

2A.1 Some Subsection

2A.1.1 Some Subsubsection

2B Some Section

2B.1 Some Subsection

2B.2 Some Subsection

3 Some Section

3.1 Some Subsection

I think the idea would be to create a new \section-like command, or set of commands, that allows the creation of a new section with a custom letter attached to it (or with something that tracks if the previous section has a letter). However, this command should not affect the usual \section command as I still want to be able to use the usual numbering before and after the subdivided section (or sections).

I have tried to implement the case where I divide a single section into two (A and B) using the approach of the accepted answer in this question. However, this answer is thought for a document where all sections are divided into A and B, while I just want to divide one section. Therefore, after using the new command they create (\sectionB), if I use \section again a letter is still added to the numbering.

Any help would be much appreciated.

Best Answer

You could enclose the changes in the section counters in an environment to be used like amsmath's subequations environment. I think the following example should do what you wanted.

\documentclass{article}
\newcounter{outersection}
\newenvironment{dividedsection}{%
    \let\oldthesection\thesection
    \setcounter{outersection}{\value{section}}
    \stepcounter{outersection}
    \setcounter{section}{0}
    \renewcommand{\thesection}{\arabic{outersection}\Alph{section}}
}{%
    \setcounter{section}{\value{outersection}}
    \renewcommand{\thesection}{\oldthesection}
}
\begin{document}
\section{A section}
\begin{dividedsection}
\section{Half of a divided section}
\subsection{A subsection}
\subsection{Another subsection}
\section{The other half}
\end{dividedsection}
\section{Another section}
\end{document}