1

I need to insert a very large figure which will occupy the whole page, so I need to remove the heading of the page where the figure is. I do this with code:

\documentclass[a4paper,12pt,twoside]{book}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{lipsum}
\usepackage{graphicx}

\pagestyle{headings}

\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}

The result is that the page where the figure is has the heading but one of the pages before the page of the figure doesn't have the heading. It removes the wrong heading of the page. How should I resolve the problem?

enter image description here enter image description here

11

2 Answers 2

1

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}
5
  • Hm, image is push to the end of document, second and last page use empty page style. If I change placement option to !ht figure is on third page, but empty page style is activated on the second page. It works correctly if figure is inserted after third page after chapter title.
    – Zarko
    May 23, 2022 at 10:50
  • Hello. Thanks for your reply. But the heading style can't be changed as it is designed by the editor of the journal. How can I resolve this problem without changing the default heading, just make the heading disappeared here?
    – Y. zeng
    May 23, 2022 at 10:50
  • If the heading style is designed by the editor and if you are not allowed to change it, then the problem probably can't be changed. But if you are allowed to use fancyhdr, you can use it to emulate the used style, and use my solution to suppress it on the figure page. May 23, 2022 at 19:17
  • Okay. I just want to modify this page. From your answer, it seems to change every figure with [p], which is beyond my need. Is there a way to just remove this page's heading?
    – Y. zeng
    May 24, 2022 at 0:14
  • I have added an example, where only one page has the headers suppressed. May 24, 2022 at 22:30
0

I think you first has to go to create a new page, than set the pagestyle to empty with the command \thispagestyle{empty} that you already used and then insert the figure with the placement command here like this \begin{figure}[!h].

In my opinion the "clean" way would be to declare a new page environment for that and then insert the image directly in that env.

3
  • I add \newpage before \begin{figure}[p], but there is nothing different.
    – Y. zeng
    May 23, 2022 at 10:53
  • Pls try \clearpage
    – deniz
    May 24, 2022 at 7:56
  • \clearpage can't resolve the problem.
    – Y. zeng
    May 25, 2022 at 1:12

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.