11

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.

  • 1
    Welcome to TeX.sx! Is it that chapter only? Are you using hyperref? What document class? – egreg May 01 '13 at 23:56
  • I think the answers here can be made to work in this case: http://tex.stackexchange.com/q/110424/10679 (So, I'd regard this as an abstract duplicate, although I am not flagging it as such, for now.) – kan May 02 '13 at 00:34

1 Answers1

9

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.

Werner
  • 603,163