Your figure is typeset on a "page of floats", and unfortunately, LaTeX uses the headers/footers definition of the previous "normal" page for these.
However, fancyhdr
has a special command for detecting that we are on a page of floats, and then we can make the header conditional on this. In the following example I use the headings
option that fancyhdr
has (in version 4 and later) to duplicate the headings
style. I then redefine the headers so that they will be empty on all float pages.
\documentclass[a4paper,12pt,twoside]{book}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{lipsum}
\usepackage{graphicx}
\usepackage[headings]{fancyhdr} % at least version 4
\pagestyle{headings}
\renewcommand{\headrule}{} % eliminate the line under the header
\fancyhead[LE,RO]{\iffloatpage{}{\thepage}}
\fancyhead[RE]{\iffloatpage{}{\slshape\leftmark}}
\fancyhead[LO]{\iffloatpage{}{\slshape\rightmark}}
\begin{document}
\chapter{Sample Chapter}
\section{New section}
\lipsum{1-6}
\begin{figure}[p]
\thispagestyle{empty}
\caption{hello}
\end{figure}
\lipsum{2-5}
\end{document}
Now if you want to suppress the headers only on one page, you can use a different test: just check the page number. In order not to have to guess the page number, or look at the printed copy, you can use a label. The refcount
package has a command \getpagerefnumber
to get the numerical vale of the page number of the label, that can be used in numerical comparisons.
I have put the label of the special page in a macro, so that you can repeat the process for later pages if so required.
\documentclass[a4paper,12pt,twoside]{book}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{lipsum}
\usepackage{graphicx}
\usepackage[headings]{fancyhdr} % at least version 4
\usepackage{refcount}
\usepackage{ifthen}
\newcommand{\whichlabel}{specialfig}
% \checkpage{value on special page}{value on other pages}
\newcommand{\checkpage}[2]{%
\ifthenelse{\thepage=\getpagerefnumber{\whichlabel}}{#1}{#2}%
}
\renewcommand{\headrule}{} % eliminate the line under the header
% Don't print headers on the special page.
% If you later want to do the same on another page, just give it a new \label
% and \renewcommand{\whichlabel}{new label}
\fancypagestyle{headings}{
\fancyhead[LE,RO]{\checkpage{}{\thepage}}
\fancyhead[RE]{\checkpage{}{\slshape\leftmark}}
\fancyhead[LO]{\checkpage{}{\slshape\rightmark}}
}
\pagestyle{headings}
\begin{document}
\chapter{Sample Chapter}
\section{New section}
ref on page~\pageref{specialfig}.
\lipsum[1-6]
\begin{figure}[p]
\caption{hello without headers}\label{specialfig}
\fbox{\rule{0.9\textwidth}{0pt}\rule{0pt}{0.9\textheight}}
\end{figure}
\lipsum[7]
\begin{figure}[p]
\caption{hello with headers}
\fbox{\rule{0.9\textwidth}{0pt}\rule{0pt}{0.9\textheight}}
\end{figure}
\lipsum[2-5]
\end{document}
https://theswissbay.ch/pdf/Gentoomen%20Library/Extra/D._Knuth-The_TeXbook.pdf