2

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\headrulewidth{0pt}
\renewcommand\footrulewidth{0pt}
\fancyfoot[C]{\thepage}
}
\fancypagestyle{plain}{
\lhead[\rm\thepage]{\fancyplain{}{\nouppercase{\sl{\bf{\leftmark}}}}}
\rhead[\rm\thepage]{\fancyplain{}{\nouppercase{\sl{\bf{\rightmark}}}}}
\chead{}\lfoot{}\rfoot{}\cfoot{}
\renewcommand{\headrulewidth}{0.1mm}%
\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}
4
  • 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
    – touhami
    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
2

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{}
  \renewcommand{\headrulewidth}{0pt}
}
% First page of chapter style
\fancypagestyle{onlycount}
{
  \fancyhf{}
  \renewcommand\headrulewidth{0pt}
  \renewcommand\footrulewidth{0pt}
  \fancyfoot[C]{\thepage}
}

\fancypagestyle{plain}{
  \lhead[\rm\thepage]{\fancyplain{}{\nouppercase{\textsl{\bfseries{\leftmark}}}}}
  \rhead[\rm\thepage]{\fancyplain{}{\nouppercase{\textsl{\bfseries{\rightmark}}}}}
  \chead{}\lfoot{}\rfoot{}\cfoot{}
  \renewcommand{\headrulewidth}{0.1mm}%
  \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}

enter image description here

2
  • you can also patch chapter command
    – touhami
    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
1

this is a way

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

\fancyhf{}
\lhead{\nouppercase{\textsl{\bfseries{\leftmark}}}}
\rhead{\nouppercase{\textsl{\bfseries{\rightmark}}}}
\fancyfoot[C]{\thepage}
\renewcommand{\headrulewidth}{0.1mm}
\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}
3
  • Ah, even shorter than mine ;-) (+1)
    – user31729
    Apr 23 '15 at 21:52
  • 1
    @ChristianHupfer i just answer question tex.stackexchange.com/questions/240238/… usuelly i don't use xpatch but i learn from you
    – touhami
    Apr 23 '15 at 21:55
  • xpatch and xparse are Swiss knives ;-)
    – user31729
    Apr 23 '15 at 21:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.