0

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: content page 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)

ipcamit
  • 115
  • welcome to tex.sx. in your definition of \startsubchapters you 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
  • You're looking at the wrong question: https://tex.stackexchange.com/questions/229068/appending-alphanumeric-character-to-chapter-numbers has better answers. – egreg Jul 19 '17 at 21:20

1 Answers1

1

examine your definition of \startsubchapter:

\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
}

the first time the redefined \chapter is used, it will have the value of the previous chapter, and furthermore, that will never change. the chapter counter does need to be stepped -- just once -- when you start the group of subchapters.

this can be accomplished by using a switch to indicate a new group, like this, for example:

\newif\iffirstsubchapter
\firstsubchaptertrue

then add some code to use it just before setting up \oldchapter:

  \iffirstsubchapter
    \firstsubchapterfalse
  \fi
  \let\oldchapter\chapter

finally, add a reversal to the definition of \stopsubchapters:

  \firstsubchaptertrue

that can go anywhere in the definition. (i'd put it as the last thing.)