I want to divide my chapters into sub chapters in same fashion as described in this question: Dividing chapters into ch. 1, ch. 2a, ch. 2b, ch. 3 etc
However I am not getting correct results. while Chapter name/counts are fine, subsections are incorrectly numbered.
Consider the modified file as provided in the accepted answer to above question:
\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}
\section{one one}
\section{one two}
\startsubchapters
\chapter{Second sub-chapter}
\section{2 A one}
\section{2 A two}
\chapter{Second sub-chapter}
\section{2 B one}
\section{2 B two}
\stopsubchapters
\chapter{Third chapter}
\chapter{Fourth chapter}
\end{document}
(I just added sections nothing more)
Provides me with following output:
It should be section 2A.1, 2B.1 etc. instead of 1A.1 1B.1 etc.
What am I doing wrong?
(compiled using pdfTeX 3.14159265-2.6-1.40.17 (TeX Live 2016/W32TeX), on windows)
\startsubchaptersyou have the command\let\oldchapter\chapter%(you don't need the%, by the way). that should only happen on subchapters after the first, since the first in a group really should step the chapter counter. you might set a switch to indicate whether the first in a group has been processed yet; such a switch can be turned off at\stopsubchapters. – barbara beeton Jul 19 '17 at 20:53