6

I'm writing a book and I wanted to add sub-chapters like :

Chapter 1

Chapter 2

Chapter 3.1

Chapter 3.2

Chapter 3.3

Chapter 4

I've quite found an answer there but it's not working the way I wanted. Is someone having an idea ?

  • 1
    Welcome to TeX.SX! What is wrong with \section??? A \section is a subchapter and if the section counter is correctly set up, it's 3.1, 3.2, 3.3 etc. Or redefine the chapter counter –  Jun 11 '16 at 15:23
  • Please tell us how a sub-chapter is supposed to differ from a section. Please also provide more details about how/why the earlier answer you've provided a link to is "not working the way I wanted." What exactly do you want? – Mico Jun 11 '16 at 15:34
  • @Mico: Too late, egreg closed it already ;-) –  Jun 11 '16 at 15:44

1 Answers1

5

A manual setup, not very convenient, by storing the chapter number and restoring it later on.

(In this example, the chapter number width in the ToC should be increased, e.g. with \addtolength{\cftchapnumwidth}{5pt} from tocloft package)

\documentclass{book}



\newcounter{subchapterusage}

\makeatletter
\let\latex@@thechapter\thechapter
\@addtoreset{chapter}{subchapterusage}% Reset the chapter counter if subchapterusage is stepped

\newcommand{\PrepareForSubchapterUsage}{%
  \xdef\chapvalue{\the\numexpr\number\value{chapter}+1}
  \stepcounter{subchapterusage}%
  \renewcommand{\thechapter}{\chapvalue.\latex@@thechapter}
}

\newcommand{\RestoreToChapterUsage}{%
  \setcounter{chapter}{\chapvalue}
  \renewcommand{\thechapter}{\latex@@thechapter}
}

\makeatother



\usepackage{hyperref}


\begin{document}
\tableofcontents

\chapter{Foo}
\chapter{Foobar}

\PrepareForSubchapterUsage
\chapter{Intermediate Chapter with Strange Counting}
\section{Foo section}
\chapter{Another intermediate Chapter with Strange Counting}

\chapter{Yet another intermediate Chapter with Strange Counting}
\RestoreToChapterUsage
\chapter{Foo continued}

\end{document}

enter image description here

  • Of course \section is much easier! –  Jun 11 '16 at 15:43
  • Thank you, it's working very well, doing exactly what I was looking for. I just had to increase the width of the chapter and the sections into the ToC with your suggestion. – bastantoine Jun 11 '16 at 17:11
  • I know that \section works well, but I already use it inside my chapters – bastantoine Jun 11 '16 at 17:14
  • @BastienAntoine: I see -- but actually, there's no concept of subchapters actually. Happy TeXing anyway! –  Jun 11 '16 at 17:51