1

I have a problem with the footer ruler on the first page of each chapter, it doesn't show whilst for the the second and following page of each chapter the ruler occurs. I found the answer: https://tex.stackexchange.com/a/344092/44119 but this is for a scrreprt and I use book. In book the \chapterpagestyle does not exist.

The first page:

enter image description here

The subsequent pages:

enter image description here

My MWE:

\documentclass[twoside]{book}
\usepackage{lipsum}                                                                                                                 
\usepackage{fancyhdr}
\pagestyle{fancyplain}
\fancyhead[LE]{\fancyplain{}{\bfseries\thepage}}
\fancyhead[CE]{\fancyplain{}{}}
\fancyhead[RE]{\fancyplain{}{\bfseries\leftmark}}
\fancyhead[LO]{\fancyplain{}{\bfseries\rightmark}}
\fancyhead[CO]{\fancyplain{}{}}
\fancyhead[RO]{\fancyplain{}{\bfseries\thepage}}
\fancyfoot[LE]{\fancyplain{\bfseries\thepage}{\bfseries\thepage}}
\fancyfoot[CE]{\fancyplain{}{}}
\fancyfoot[RE]{\fancyplain{\bfseries\scriptsize Generated }{\bfseries\scriptsize Generated }}
\fancyfoot[LO]{\fancyplain{\bfseries\scriptsize Generated }{\bfseries\scriptsize Generated }}
\fancyfoot[CO]{\fancyplain{}{}}
\fancyfoot[RO]{\fancyplain{\bfseries\thepage}{\bfseries\thepage}}
\renewcommand{\footrulewidth}{0.4pt}

\begin{document}

\chapter{My Chapter} \lipsum[1] \newpage \lipsum[1] \newpage \lipsum[1]

\end{document}

So my question is how to solve this:

  • what is the alternative for \chapterpagestyle in book

or

  • how to directly solve it in the given MWE?
albert
  • 1,313
  • \fancypagestyle{plain}{\pagestyle{fancyplain}} should work. – Ulrike Fischer Oct 09 '20 at 09:41
  • I replaced \pagestyle{fancyplain} at line 4 with \fancypagestyle{plain}{\pagestyle{fancyplain}} it does show the footer ruler on the first page, but has as effect that I get a header on page 1, no footers on subsequent pages and the header ruler is gone at the pages 2 and further. – albert Oct 09 '20 at 09:50
  • I didn't say to replace anything. Simply add it. – Ulrike Fischer Oct 09 '20 at 09:57
  • Sorry this was not clear from your comment, I now added \fancypagestyle{plain}{\pagestyle{fancyplain}} after \pagestyle{fancyplain}, looks a bit better, but now I get a header on page 1 of the chapter, which I wouldn't like to have. – albert Oct 09 '20 at 10:02
  • Sorry it was unclear that you want only the footer. You probably can do \fancypagestyle{plain}{\pagestyle{fancyplain}\fancyhead{}}. Basically you have to redefine plain style, see the fancyhdr documentation. – Ulrike Fischer Oct 09 '20 at 10:05
  • Looks to me that I now still get the ruler with the first page. I also tried @Bernard his answer, this looks promising. – albert Oct 09 '20 at 10:12

1 Answers1

1

As the first page of a chapter is in the plain style, you have to redefine it. I took the opportunity to simplify the code for the fancyplain style:

\documentclass[twoside]{book}
\usepackage{lipsum}
\usepackage{fancyhdr}
\pagestyle{fancyplain}%
\renewcommand{\footrulewidth}{0.4pt}
%%%
\fancypagestyle{fancyplain}{%
\fancyhf{}
\fancyhead[LE, RO]{\bfseries\thepage}
\fancyhead[LO]{\bfseries\rightmark}
\fancyhead[RE]{\bfseries\leftmark}
\fancyfoot[LE, RO]{\bfseries\thepage}
\fancyfoot[LO, RE]{\bfseries\scriptsize Generated}
}
%%%
\fancypagestyle{plain}{%
\fancyhf{}
\fancyfoot[LE, RO]{\textbf{\thepage}}
\fancyfoot[LO, RE]{\bfseries\scriptsize Generated}
\renewcommand{\headrulewidth}{0pt}}

\pagestyle{fancyplain}%

\begin{document}

\chapter{My Chapter} \lipsum[1] \newpage \lipsum[1] \newpage \lipsum[1]

\end{document}

enter image description here

Bernard
  • 271,350
  • This looks promising, have to test it in my bigger code base. – albert Oct 09 '20 at 10:13
  • This works in my normal cases OK, though when I have a \part part I want to suppress the header and footer. I didn't yet succeed. I'll create a new issue for that problem. – albert Oct 09 '20 at 11:03
  • You might add a \thispagestyle{empty} immediately after \part. – Bernard Oct 09 '20 at 11:07
  • Unfortunately this didn't work for me, see my new question: https://tex.stackexchange.com/questions/566056/footer-ruler-on-first-page-in-fancyhdr-with-book-but-not-in-part-part – albert Oct 09 '20 at 11:26