# Adding page number to the even page right after \part

Friends, I've never used \part{} before, so bear with me. =)

Consider the following code:

\documentclass[twoside]{book}
\usepackage{lipsum}

\begin{document}

\pagestyle{empty}
\begin{titlepage}
My title page.
\end{titlepage}

\cleardoublepage
\pagestyle{plain}

\frontmatter
\tableofcontents
\clearpage
\mainmatter

\part{Hello World}
\chapter{Test one}
\lipsum[1]
\section{My section one}
\lipsum[1]

\part{Goodbye World}
\chapter{Test two}
\lipsum[1]
\section{My section two}
\lipsum[1]

\end{document}


I'd like to have page numbers in the even pages right after the Part x titles. It would be pages 6 and 10 of my example.

I could redefine the empty pagestyle to act as plain, but I didn't want to do that. In fact, I tried that - and it works - but I also need empty pagestyles in my original document.

I suppose \part is like a book division, so it should look like another "cover" (what would explain why there's no number in the hm... back of the page). In my particular case, I need that number to be in there.

Does anybody have an idea?

-

But you can redefine the empty page style to be plain and do it locally using \begingroup, \endgroup; for example (only the page following part one will receive number):

\documentclass[twoside]{book}
\usepackage{lipsum}

\begin{document}

\pagestyle{empty}

\begin{titlepage}
My title page.
\end{titlepage}

\cleardoublepage

\pagestyle{plain}

\frontmatter

\tableofcontents

\clearpage

\mainmatter

\begingroup
\makeatletter
\let\ps@empty\ps@plain
\makeatother

\part{Hello World}

\endgroup\chapter{Test one}
\lipsum[1]

\section{My section one}
\lipsum[1]

\part{Goodbye World}

\chapter{Test two}
\lipsum[1]

\section{My section two}
\lipsum[1]

\end{document}


### Remark:

As Frank Mittelbach says in his comment, introducing groupings that go across the LaTeX concepts can be "dangerous". In this particular case, there's no harm, but in case of chapter and section one might see side effects already (the indentation is no longer suppressed for example).

-
Wow! Thanks for the enlightenment, Gonzalo! I didn't know I could redefine the scope locally. That's certainly a great solution! – Paulo Cereda Aug 26 '11 at 17:36
On the whole it is not a good idea to do something like this. Introducing groupings that go across the LaTeX concepts will eventually generate issues down the road. For part there is no harm, but in case of chapter and section you might see side effects already (the indentation is no longer suppressed for example). So this is not the solution that should be accepted as it gives dangerous advice. – Frank Mittelbach May 2 '12 at 16:46
@FrankMittelbach: I agree that using groupings could be dangerous (not in the case of the answer I gave), but I don't see that grouping will result in inappropriate indentation of the first line after a sectional unit: \documentclass{book} \usepackage{lipsum} \begin{document} \begingroup \chapter{Test one} \lipsum[1] \section{My section one} \lipsum[1] \endgroup \end{document} behaves as one would expect regarding indentation. Am I misunderstanding your comment? – Gonzalo Medina May 2 '12 at 23:19
@Gonzalo in your example you moved the \endgroup to the natural end of the chapter (which is equiv to a chapter environment - which is ok). But in the answer your group ends directly after the heading title - which is not ok. So move the \endgroup directly after chapter to see the effect. – Frank Mittelbach May 3 '12 at 6:58
@FrankMittelbach: Oh, now I see. Thanks. I will add some warning message to my answer. – Gonzalo Medina May 3 '12 at 20:35

Here is a patch with etoolbox for numbered pages following part pages:

\usepackage{etoolbox}
\makeatletter
\patchcmd{\@endpart}{empty}{plain}
\makeatother


The macro \@endpart causes the empty page style, which is replaced by plain by this patch.

-
Thanks Stefan! You guys are awesome, we can always learn new things every day! – Paulo Cereda Aug 26 '11 at 17:46

You could also redefine the macro \@endpart from the file book.cls, which looks like:

\def\@endpart{\vfil\newpage
\if@twoside
\if@openright
\null
\thispagestyle{empty}% the instruction I believe you want to remove
\newpage
\fi
\fi
\if@tempswa
\twocolumn
\fi}


If I understand your explanation correctly, all you require is to suppress the instruction \thispagestyle{empty}. This may be achieved by (i) commenting out this instruction in the file book.cls and saving the class file to a new file, say, "mybook.cls" -- note that it is very much against the LPPL to save the change under the existing file name -- or (ii) by providing a modified definition for this macro in the preamble of your document, sandwiched between \makeatletter and \makeatother instructions:

\makeatletter
\def\@endpart{\vfil\newpage
\if@twoside
\if@openright
\null
%%\thispagestyle{empty}% this instruction is now commented out
\newpage
\fi
\fi
\if@tempswa
\twocolumn
\fi}
\makeatother


See also @StefanKottwitz's answer for a way to achieve this objective using the tools of the etoolbox package.

-
TBH, I was tempted on commenting the pagestyle instruction, but since I'm still in the beginning of the learning process, I would not even know where to start. =) Thankfully, there are better (should I say safer) ways to solve my issue. Thanks for posting the book class code snippet, it's great to know how things work under the hood. – Paulo Cereda Aug 26 '11 at 18:08
Changing book.clswithout marking it as private (for example by renaming it) is against its license LPPL. So this is not the way to go. The correct solution is to patch \@endpart either in the preamble of your document or in a package of your own. The shortest way to do this is as in @Stephan's answer. – Frank Mittelbach May 2 '12 at 16:52
@FrankMittelbach -- Thanks for clarifying the legal situation. I'll modify my answer to alert readers to the fact that they should not modify the file book.cls without renaming the copy to something different. – Mico May 2 '12 at 18:04

In memoir, this is very simple (that's why I love memoir). In the preamble:

\aliaspagestyle{afterpart}{plain}  % (Instead of plain, whatever you want)

-
Fantastic, Brent! :) I'm considering migrating to memoir. :) – Paulo Cereda May 4 '12 at 0:14