How to split a latex document using parts and chapters

I'm trying to make a PDF document, using the book class, divided like this:

• Part: 1
• Chapter 1
• Chapter 2
• Etc.
• Part: 2
• Chapter 1
• Chapter 2
• Etc.

How do I do this without the break in page numbers?

-

migrated from stackoverflow.comNov 22 '11 at 16:00

This question came from our site for professional and enthusiast programmers.

Sorry for not being specific enough. I'm using book class, and with "messing up the numbers" I mean that I don't want a break in the page numbers. So I want them to be continuously and don't start over whenever I begin a new part. –  Simon Nov 22 '11 at 15:36
I've updated the question with this information :). –  Lewis Norton Nov 22 '11 at 15:41

There is nothing fancy about creating such a document in LaTeX. You can use either the report or book document class (or another, like memoir). The example below uses the book document class.

\documentclass{book}
% Comment the following to have chapters numbered without interruption (numbering through parts)
\begin{document}
\tableofcontents
\part{First part}
\chapter{First chapter}
\chapter{Second chapter}
%...
\chapter{Last chapter}
\part{Second part}
\chapter{First chapter}
\chapter{Second chapter}
%...
\chapter{Last chapter}
\part{Last part}
\chapter{First chapter}
\chapter{Second chapter}
%...
\chapter{Last chapter}
\end{document}


The \tableofcontents shows the document structure. In order to have this structure accurately represent the document contents, you need to compile your code at least twice. Similar counter-resetting functionality is provided by the cnhgcntr package via \counterwithin*{chapter}{part}, although LaTeX provides its own \@addtoreset{<slave>}{<master>}. Here is some information on counter resetting: Master and slave counters

If you want to have the numbering continue through the parts (rather than having it numbered on a per-part basis), you can comment the 3rd line of code.

-
Thanks a lot! The "\part{}"-command and the last part with uncomment the 3rd line did the job –  Simon Nov 22 '11 at 16:07
@Simon: I've reverted my answer to have the chapters numbered on a per-part basis, rather than displaying it with the possibility to number as such. I know it already solved your problem; I just wanted to be consistent in the presentation, as reflected in your original question. –  Werner Nov 22 '11 at 17:00
do you know how to remove the blank page after the part? Right now it is: part 1 blank page chapter 1 part 2 blank page chapter 1 I have tried with \makeatletter\@openrightfalse \part{A} \@openrighttrue\makeatother But that didn't help. –  Simon Nov 23 '11 at 10:17