3

I using the book class for my thesis and I want to insert a "This page intentionally left blank" message on the left pages when using openright. However, I only want to display this message in the frontmatter of my document, and use the headers set by fancyhdr in the mainmatter on an otherwise potantially empty page. I'm using the code below, adapted from this answer:

\documentclass[11pt,openright]{book}
\makeatletter
\def\cleardoublepage{\clearpage\if@twoside%
    \ifodd\c@page\else
    \vspace*{5cm}
    \begin{center}
        This page intentionally left blank.
    \end{center}
    \thispagestyle{empty}
    \newpage
    \if@twocolumn\hbox{}\newpage\fi\fi\fi
}
\makeatother
\usepackage{fancyhdr}
\fancyhf{}
\fancyhead[LE,RO]{\thepage}
\fancyhead[CE]{\textit{\MakeUppercase{My name}}}
\fancyhead[RE]{}
\fancyhead[LO]{}
\fancyhead[CO]{\textit{\MakeUppercase{\The title}}}
\pagestyle{fancy}

\title{The title}
\author{My name}
\date{\today}

\begin{document}
\maketitle
\frontmatter
\chapter{Abstract}
\mainmatter
\chapter{The first chapter}
\chapter{The second chapter}
\end{document}

I tried to put \if@mainmatter in different places in the definition of the cleardoublepage command, but I couldn't get it to work. Any help? Thanks.

avs
  • 282

2 Answers2

4

Redefinition can be done inside a group that only contains the front matter:

\documentclass[11pt,openright]{book}

\usepackage{fancyhdr}
\fancyhf{}
\fancyhead[LE,RO]{\thepage}
\fancyhead[CE]{\textit{\MakeUppercase{My name}}}
\fancyhead[RE]{}
\fancyhead[LO]{}
\fancyhead[CO]{\textit{\MakeUppercase{The title}}}
\pagestyle{fancy}

\title{The title}
\author{My name}
\date{\today}

\begin{document}

\begingroup
\makeatletter
\def\cleardoublepage{\clearpage\if@twoside%
    \ifodd\c@page\else
    \vspace*{5cm}
    \begin{center}
        This page intentionally left blank.
    \end{center}
    \thispagestyle{empty}
    \newpage
    \if@twocolumn\hbox{}\newpage\fi\fi\fi
}
\makeatother
\maketitle
\frontmatter
\chapter{Abstract}

\endgroup
\mainmatter
\chapter{The first chapter}
\chapter{The second chapter}
\end{document}
gigi
  • 402
  • This works after swapping \endgroup and \mainmatter. Otherwise, I don't get the message on the page after the abstract. I will wait a bit longer for an answer that changes the definition of the \cleardoublepage command and fits in the preamble. Otherwise I will accept your answer. Thanks! – avs Jun 21 '19 at 11:31
3

This is very close to what you had (and you probably attempted). I was able to make \if@mainmatter work. The other difference is that \frontmatter needed to come before \maketitle.

\documentclass[openright]{book}
\makeatletter
\def\cleardoublepage{\clearpage%
\if@twoside%
 \ifodd%
  \c@page%
 \else%
  \if@mainmatter%
   \hbox{}%
  \else%
   \vspace*{5cm}
   \begin{center}This page intentionally left blank.\end{center}
   \thispagestyle{empty}
  \fi%
  \newpage%
  \if@twocolumn\hbox{}\newpage\fi%
 \fi%
\fi%
}
\makeatother
\usepackage{fancyhdr}
\fancyhf{}
\fancyhead[LE,RO]{\thepage}
\fancyhead[CE]{\textit{\MakeUppercase{My name}}}
\fancyhead[RE]{}
\fancyhead[LO]{}
\fancyhead[CO]{\textit{\MakeUppercase{\The title}}}
\pagestyle{fancy}

\title{The title}
\author{My name}
\date{\today}

\begin{document}
\frontmatter
\maketitle
\chapter{Abstract}
\mainmatter
\chapter{The first chapter}
\chapter{The second chapter}
\end{document}

Another possibility (but more work) would be to \let\mainmattercleardoublepage=\cleardoublepage, then do your redefinition, and redefine \mainmatter to also include \let\cleardoublepage=\mainmattercleardoublepage.

Teepeemm
  • 6,708