15

I have a preface for my document and instead of calling it Chapter 1, or using \chapter* to not include it in the table of contents, I would like it so it instead of a 1 I have a P. Then normal counting resumes - a bit like appendices.

so my table of contents looks like:

P Preface
   P.1 Stuff
   P.2 More Stuff

I    All about stuff

1 Stuff in itself
   1.1 Does stuff exist
   1.2 Does stuff matter
      1.2.1 The ethical implications of the non-existence of stuff


etc.

EDIT: Extra problem: I also want to not have it say:

Chapter P
 Preface

but just

 Preface

at the start of the preface - perhaps add to the table of contents manually - but my naive attempt didn't work so well.

Lucas
  • 928
  • 3
  • 11
  • 20
  • 4
    I just see that you have asked several questions and have received good answers to some of them, but you haven't accepted any. Please consider marking one of the answers as ‘Accepted’ by clicking on the tickmark below their vote count. This shows which answer helped you most (and it assigns reputation points to the author of the answer and to you!). – Gonzalo Medina Apr 06 '12 at 02:03

2 Answers2

21

You should manually switch the chapter counter representation before the out-of-the-ordinary chapters. Here's the basic idea (remember, the chapter counter is incremented at the start of \chapter):

\setcounter{chapter}{15}% Equivalent to "letter O"
\renewcommand{\thechapter}{\Alph{chapter}}%
\chapter{Preface}
%...
\setcounter{chapter}{8}% Equivalent to "letter H"
\chapter{All about stuff}
%...
\setcounter{chapter}{0}%
\renewcommand{\thechapter}{\arabic{chapter}}%
\chapter{Stuff in itself}
%...

Here's a more complete example, using \chapter* for the Preface, and \part for "All about stuff":

enter image description here

\documentclass{book}
\begin{document}
\tableofcontents

\setcounter{chapter}{16}% Equivalent to "letter P"
\renewcommand{\thechapter}{\Alph{chapter}}%
% Alternatively, replace the above two commands with
%   \renewcommand{\thechapter}{P}
% as in Gonzalo's answer - it's just simpler.
%\chapter{Preface}
\chapter*{Preface}
\addcontentsline{toc}{chapter}{\numberline{P}Preface}
%...
\part{All about stuff}
%...
%\setcounter{chapter}{0}%
%\renewcommand{\thechapter}{\arabic{chapter}}%
\chapter{Stuff in itself}
%...
\end{document}
Werner
  • 603,163
  • Sweet, worked like a charm! If I could give bonus points for giving me the right number for P I would :) – Lucas Apr 06 '12 at 00:08
  • Any ideas about my edit? – Lucas Apr 06 '12 at 00:17
  • @Lucas: Do you want to have remove the P from the ToC as well? – Werner Apr 06 '12 at 01:21
  • Nope. It was just that Chapter P looks rather silly. Gonzalo's solution seems to have sorted things. – Lucas Apr 06 '12 at 01:23
  • @Lucas: I've updated my answer to accommodate your latest request. Using \chapter* and then adding the necessary details in the ToC via \addcontentsline. The fake \numberline{P} preserves your required "Chapter P" in the ToC. – Werner Apr 06 '12 at 01:29
  • @GonzaloMedina: Sha-zam. Thanks, I forget that sections are to be included. I've updated it accordingly. – Werner Apr 06 '12 at 02:07
  • This solution does not work when trying to refer to the chapter elsewhere in the document using links created by the pdftex package. After much debugging, I think what is happening is that if there are two "chapter 0s" (to get a chapter labeled A using the above), all links will refer to the first. So I had an appendix at the end called A using this trick, but all references in my document link to the "first chapter 0" which is the first chapter. – Tommy Sep 08 '14 at 16:50
  • @Tommy: You're probably referring to the hyperref package. And yes, this is a common issue when fiddling with and reusing counters - they're used when establishing the hyperlinks internal to the document. I'll update my answer to accommodate for this (even though it was not part of the original question). – Werner Sep 08 '14 at 16:58
21

You can simply locally redefine the representation for the chapter counter and then set the counter to the proper value for the regular chapters. The titlesec package can be used to locally redefine the chapter title format:

\documentclass{book}
\usepackage{titlesec}
\begin{document}

\tableofcontents
\begingroup
\renewcommand\thechapter{P}
\titleformat{\chapter}[display]
{\normalfont\huge\bfseries}{}{20pt}{\Huge}
\chapter{Preface}
\section{Preface Section One}
\section{Preface Section Two}
\endgroup

\part{First Part}
\addtocounter{chapter}{-1}
\chapter{First Regular Chapter}
\section{Regular Section One One}
\section{Regular Section One Two}

\end{document}

enter image description here

Gonzalo Medina
  • 505,128
  • If you are having issues with mixed up bookmarks in your PDF produced by the hyperref package use \usepackage[hypertexnames=false]{hyperref} (see http://tex.stackexchange.com/questions/6098/wrong-hyper-references-after-resetting-chapter-counter/6102#6102) – Alex Trueman Nov 29 '16 at 02:53