[Tex/LaTex] Dividing chapters into ch. 1, ch. 2a, ch. 2b, ch. 3 etc

chaptersnumberingsectioningtable of contents

I'm typesetting a book and one of the chapters separates into two chapters so I need it to count like so:

chapter 1
---------

chapter 2a
----------

chapter 2b
----------

chapter 3
---------

chapter 4
---------

I saw an almost solution here. But this solution doesn't allow me to continue with my non-separated chapter counting.

This is chapters only, the sections are not numbered, and I'm using the book class with the hyperref package.

Best Answer

If you're using one of the standard document class that provides \chapter (like book or report), then the following works:

enter image description here

\documentclass{report}
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
%\usepackage{hyperref}% http://ctan.org/pkg/hyperref
\newcounter{subchapter}\renewcommand{\thesubchapter}{\alph{subchapter}}
\makeatletter
% \patchcmd{<cmd>}{<search>}{<replace>}{<success>}{<failure>}
\newcommand{\updatechaptercounter}{}
\patchcmd{\@chapter}{\@afterheading}{\updatechaptercounter\@afterheading}{}{}% Regular patch of \@chapter
%\patchcmd{\Hy@org@chapter}{\@afterheading}{\updatechaptercounter\@afterheading}{}{}% Hyperref patch of \@chapter
\makeatother
\providecommand{\theHchapter}{}%
\newcommand{\startsubchapters}{%
  \setcounter{subchapter}{0}% Reset sub-chapter numbering
  \renewcommand{\thechapter}{\arabic{chapter}\thesubchapter}% Update chapter number display
  \renewcommand{\theHchapter}{\arabic{chapter}\thesubchapter}% Update chapter number display (for hyperref)
  \renewcommand{\updatechaptercounter}{\addtocounter{chapter}{-1}}% Update chapter number
  \let\oldchapter\chapter%
  \renewcommand{\chapter}{\stepcounter{subchapter}\oldchapter}% Increment subchapter
}
\newcommand{\stopsubchapters}{%
  \renewcommand{\thechapter}{\arabic{chapter}}% Reset chapter numbering
  \renewcommand{\theHchapter}{\arabic{chapter}}% Reset chapter numbering (for hyperref)
  \let\chapter\oldchapter% Restore regular \chapter command
  \renewcommand{\updatechaptercounter}{}% Clear chapter counter update
  \stepcounter{chapter}% Update chapter counter
}
\begin{document}
\tableofcontents
\chapter{First chapter}
\startsubchapters
\chapter{Second sub-chapter}
\chapter{Second sub-chapter}
\stopsubchapters
\chapter{Third chapter}
\chapter{Fourth chapter}
\end{document}

The idea behind this solution is to patch \@chapter and insert a special macro \updatechaptercounter. This macro is then redefined in a specific way, depending on whether you start the sub-chapter numbering (\startsubchapters) or stop it (\stopsubchapters).

If you're using hyperref as well, then you need to update the patch as indicated in the above MWE.

Related Question