Removing fancy style from part pages

I am using the fancyhdr package to set headers and footers for the thesis. I have recently added LaTeX \parts, and defined a pagestyle for this purpose called 'partpagestyle'. As the MWE below shows, the 'onlycount' style correctly removes the header on the first page of every chapter. I have defined 'partpagestyle' to clear the formatting of fancyhdr, but it does not have the desired result. I have perused the manual (http://texdoc.net/texmf-dist/doc/latex/fancyhdr/fancyhdr.pdf) to no avail. What am I doing wrong here?

\documentclass[10pt]{report}
\usepackage{lipsum}
\usepackage{fancyhdr}

% Clear everything on part pages
\fancypagestyle{partpagestyle}
{
\fancyhf{}
}
% First page of chapter style
\fancypagestyle{onlycount}
{
\fancyhf{}
\renewcommand\footrulewidth{0pt}
\fancyfoot[C]{\thepage}
}
\fancypagestyle{plain}{
\fancyfoot[C]{\thepage}%
}
\pagestyle{plain}

\begin{document}

\begin{titlepage}
\huge \bfseries Thesis
\end{titlepage}

\chapter{Introduction}\thispagestyle{onlycount}
\lipsum[1-3]
\section{Motivation}
\lipsum[1-3]

\part{Some Part}
%\thispagestyle{partpagestyle}
%\thispagestyle{partpagestyle}

\chapter{Second Chapter}\thispagestyle{onlycount}
\lipsum[1-9]

\end{document}
• Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format.
– user31729
Apr 23 '15 at 21:16
• try to replace plain by fancy in your code Apr 23 '15 at 21:18
• Do you mean to say replacing \pagestyle{plain} by \pagestyle{fancy} etc? My code does not compile with this change. Apr 23 '15 at 21:34
• Please do not use \bf etc. Those commands are outdated
– user31729
Apr 23 '15 at 21:36

The \part macro from report.cls always has a \thispagestyle{plain} in its setup, so redefining the plain style with a header rule of thickness 0.1mm will show such one.

\fancyhf{} does only clear the individual fields of the header and footers, but not the header or footer rules. To clear this, I added \renewcommand{\headrulewidth}{0pt} to the partpagestyle definition.

This code patches the \part command to use partpagestyle instead of plain

\documentclass[10pt]{report}
\usepackage{lipsum}
\usepackage{fancyhdr}

% Clear everything on part pages
\fancypagestyle{partpagestyle}
{%
\fancyhf{}
}
% First page of chapter style
\fancypagestyle{onlycount}
{
\fancyhf{}
\renewcommand\footrulewidth{0pt}
\fancyfoot[C]{\thepage}
}

\fancypagestyle{plain}{
\fancyfoot[C]{\thepage}%
}
\usepackage{xpatch}
% Patch the \thispagestyle code within `\part
\xpatchcmd{\part}{\thispagestyle{plain}}{\thispagestyle{partpagestyle}}{}{}
\pagestyle{fancy}

\begin{document}

\begin{titlepage}
\huge \bfseries Thesis
\end{titlepage}

\chapter{Introduction}\thispagestyle{onlycount}
\lipsum[1-3]
\section{Motivation}
\lipsum[1-3]

\part{Some Part}

\thispagestyle{onlycount}
\chapter{Second Chapter}
\lipsum[1-9]

\end{document}

• you can also patch chapter command Apr 23 '15 at 21:46
• @touhami: Yes, I considered it, but you know the proverb: Leave it as an exercise ;-)
– user31729
Apr 23 '15 at 21:47

this is a way

\documentclass[10pt]{report}
\usepackage{lipsum}
\usepackage{fancyhdr}

\fancyhf{}
\fancyfoot[C]{\thepage}
\pagestyle{fancy}

\usepackage{xpatch}

\xpatchcmd{\part}{\thispagestyle{plain}}{\thispagestyle{empty}}{}{}

\begin{document}

\begin{titlepage}
\huge \bfseries Thesis
\end{titlepage}

\chapter{Introduction}
\lipsum[1-3]
\section{Motivation}
\lipsum[1-3]

\part{Some Part}

\chapter{Second Chapter}
\lipsum[1-9]

\end{document}
• Ah, even shorter than mine ;-) (+1)
– user31729
Apr 23 '15 at 21:52
• @ChristianHupfer i just answer question tex.stackexchange.com/questions/240238/… usuelly i don't use xpatch but i learn from you Apr 23 '15 at 21:55
• xpatch and xparse are Swiss knives ;-)
– user31729
Apr 23 '15 at 21:56