Change the numbering in toc and titles

sectioningtable of contentstitlesectitletoc

I am preparing a template for the PhD thesis at our institute. The thesis includes published papers as chapters and regular book chapters. I am building on the book.cls. I also have different pagestyles with fancyhdr for the chapters that are made of papers and those regular book chapters. Now I would like change the numbering of the chapters and sections in ToC and the titles as follows:

1 Introduction
  1.1 Motivation
      1.1.1 First Motivation
      1.1.2 First Motivation
  1.2 Objectives
  ...
P2 FirstPaper
  P2-1 Introduction
  P2-2 Methods
       P2-2.1 Approach
       P2-2.2 Validation
  ...
3 RegularChapter
  3.1 Introduction
  3.2 Methods
       3.2.1 Approach
       3.2.2 Validation
  ...

I guess there should be some way of redefining the \thechaper \thesection \thesubsection command during the \fancypagestyle command. I also tried to look into the titlesec package, but could not identify the commands for the numbering if there is one. Most of the stuff refers to the title formatting.

I hope I have described the problem well. Can anyone help me? Cheers!

Best Answer

EDIT: I added a more general approach, by outsourcing the relevant commands to the preamble. I had disregarded that this is not a one-off document you are writing, but a thesis template. Sorry about that. The improved approach should be more in the spirit of your question: it is less likely to result in errors, even if the chapters move around a lot in the document; it ought to be smoother for end users too, who shouldn't have to redefine internals, such as \thechapter, mid-document.

(Editing an already-accepted answer is not ideal. But I hope you'll find that the addition does not detract from the original solution.)


Welcome to TeX.SX!

Solution 1: You can redefine \thechapter before the chapter requiring special format, revert to default afterwards. This solution does not require additional packages.

\documentclass{book}

\begin{document}

\tableofcontents

\chapter{First chapter}
\section{Regular section}

\let\oldthechapter\thechapter
\renewcommand*{\thechapter}{P\oldthechapter}

\chapter{Paper – chapter}
\section{Paper – section}
\subsection{Paper – subsection}

\let\thechapter\oldthechapter

\chapter{Third chapter}
\section{Regular section}

\end{document}

Solution 2: The same result can be achieved by building a new kind of chapter (\paperchapter) around the standard \chapter. Whenever the user calls \paperchapter in the main document, the numbering format is redefined by adding a "P"; whenever a normal \chapter is called, the default format is reinstated.

Continuous numbering of chapters is preserved; starred versions and optional arguments (\paperchapter[Short Title]{Long Title}) are still usable.

\documentclass{book}

\let\oldthechapter\thechapter
\let\oldchapter\chapter

\newcommand*{\paperchapter}{\renewcommand*{\thechapter}{P\oldthechapter}\oldchapter}
\renewcommand*{\chapter}{\renewcommand*{\thechapter}{\oldthechapter}\oldchapter}


\begin{document}

\tableofcontents

\chapter{First chapter}
\section{Regular section}

\paperchapter{Paper – chapter}
\section{Paper – section}
\subsection{Paper – subsection}

\chapter{Third chapter}
\section{Regular section}

\end{document}

TOC with special formatting

Title of special chapter

Related Question