[Tex/LaTex] avoid \headrulewidth appearing at chapter beginning

fancyhdrheader-footer

I am using the following code set my headers.

\fancypagestyle{plain}
\fancyhf{}
\pagestyle{fancy}
\fancyhead{}
\fancyhead[L]{\textit{\sffamily\ifthenelse{\isodd{\value{page}}}{\leftmark}{\rightmark}}}
\fancyhead[R]{\textit{\sffamily\thepage}}
\fancyfoot[C]{}
%\headrulewidth{0.1pt}

\renewcommand{\headrulewidth}{0.1pt} 

The \headrulewidth (line below the head) is also appearing at the beginning of a chapter and I WANT TO DISABLE this.

How can I change the behaviour of the headrulewidth for the first page of a chapter?

Best Answer

You have to redefine the plain pagestyle

\documentclass{report}
\usepackage{blindtext}
\usepackage{ifthen}
\usepackage{fancyhdr}

%Redefine plain 
\fancypagestyle{plain}{%
\fancyhf{}%
\fancyfoot[C]{\thepage}%
\renewcommand{\headrulewidth}{0.0pt}%
}

\pagestyle{fancy}
\fancyhead{}
\fancyhead[L]{\textit{\sffamily\ifthenelse{\isodd{\value{page}}}{\leftmark}{\rightmark}}}
\fancyhead[R]{\textit{\sffamily\thepage}}
\fancyfoot[C]{}
%\headrulewidth{0.1pt}

\renewcommand{\headrulewidth}{0.1pt} 
\begin{document}
\blinddocument
\end{document}