# How to apply a custom pagestyle (with titlesec package) to a part of a document

I have defined a personal page style using the package titlesec. The style defined is:

\newpagestyle{myStylePage}[\large\sffamily]{\headrule
\setfoot{}{\usepage}{}
}


I want this style be applied only to all my chapters. But I don't want this style be applied to the \tableofcontents, for example. In order to solve it, I tried to define a another style:

\newpagestyle{myEmptyPage}{
\setfoot{}{\usepage}{}
}


My document follows as:

\pagestyle{myEmptyPage}

\pagenumbering{roman}

\tableofcontents
\pagenumbering{arabic}
\pagestyle{myStylePage}
\include{tex/introduction}
... etc.


My problem is that the second page of the table of contents appears with the same style as defined in myStylePage. What I am doing wrong?

-
Welcome to TeX.sx! A tip: If you indent lines by 4 spaces, they'll be marked as a code sample. You can also highlight the code and click the "code" button (with "{}" on it). Also: Please add a minimal working example (MWE) that illustrates your problem. It is considered a lot better to put in some code that will compile, as it makes it a lot easier for us to copy it into our text editor and work with it, and see exactly what it is you are trying to do. –  Silex Oct 30 '12 at 15:50
Would you please add the class you're using? –  egreg Oct 30 '12 at 17:57
Without MWE/class I'm just guessing here: Try a \newpage between \tableofcontents and \pagenumbering{arabic}. –  Stephen Oct 30 '12 at 18:22
Glad that I could help. Instead of posting a “Thank you”, the usual way here is to upvote helpful answers (with the upward pointing arrow to the left of it) and by accepting the most helpful one (by clicking on the checkmark). –  Stephen Oct 31 '12 at 9:07
@doncherry: The title is more descriptive now (without mentioning the TOC) but also quite long. If you (or anybody else) has a better idea, please implement that one. –  Stephen Nov 4 '12 at 11:39

You don't need to define a new style, since "empty headers, page number at footer center" is the plain page style, which is also used in the chapter starting pages.

So I believe that the following should suit your needs.

\documentclass{book}
\usepackage{titleps} % or titlesec with appropriate option

\newpagestyle{myStylePage}[\large\sffamily]{%
\setfoot{}{\usepage}{}%
}

\begin{document}
\frontmatter
\pagestyle{plain}

\tableofcontents

\mainmatter
\pagestyle{myStylePage}

My beautiful document

\end{document}


If you're using the report class for one sided printing, don't. :) But if you're required to do that, just add an option to the class:

\documentclass[oneside]{book}


Maybe you're using scrreprt; then use scrbook with the same commands.

In case you don't trust me and want to continue using report (or any class that hasn't \frontmatter and \mainmatter such as scrreprt), change the \frontmatter command into

\clearpage\pagenumbering{roman}


and \mainmatter into

\clearpage\pagenumbering{arabic}


but don't forget \clearpage.

-

\pagenumbering and \pagestyle are applied to the whole page where they are used, i.e. this is done as if they were used at the beginning of that page. When there is no page break at the end of the Table of Contents, \pagenumbering{arabic} \pagestyle{myStylePage} is applied to the last page of the TOC as well as to the text following below the TOC (if there is any text on the same page). A \newpage after the TOC takes care of this. A \clearpage (or \cleardoublepage) would start a new page and additionally force all floating objects to be printed, but probably there are no floats in a TOC.

-