2

I try to write a document using the report document class. I used fancypagestyle to redefine the plain page style to have custom header and footers.

Now I try to fill the document with its content, using \chapter, \section, and \subsection. The effect, that I see and which I do not expect is, that when I have enough text, that a page that started with a \chapter overflows to the next page, the page style changes to a style without header and footer. To me, it seems that the original plain page style is used again (I can see a page number at the bottom of the page).

I can workaround that, by adding \thispagestyle{plain} after \section or \subsection.

Is there some kind of mechanic involved, that switches to a different page style? What else could cause this change in the page style?

Edit: Here is a very reduced document, that shows the problem. The first page is using the plain page style, but on page 2 and the following pages, an other page style seems to be used (I think that might be the old plain style).

\documentclass[a4paper]{report}

\usepackage{titling}

\title{Test}
\author{Me}
\date{\today}
\let\documenttitle\thetitle

\usepackage[T1]{fontenc}
\usepackage{fontspec}
\usepackage{titlesec}
\usepackage{fancyhdr}
\usepackage{blindtext}

\setlength{\voffset}{-2.540cm}
\setlength{\hoffset}{-2.540cm}

\setlength{\topmargin}{2.0cm}
\setlength{\headsep}{1cm}
\setlength{\headheight}{0.5cm}

\setlength{\oddsidemargin}{2.5cm}
\setlength{\footskip}{2.9cm}

\setlength{\textheight}{23.5cm}
\setlength{\textwidth}{16.0cm}

\setlength{\marginparwidth}{0cm}
\setlength{\marginparpush}{0cm}
\setlength{\marginparsep}{0cm}

\fancypagestyle{plain}{%
    \fancyhf{}%

    \rhead{\fontsize{8.5pt}{11.5pt}\fontseries{m}\selectfont\thepage/X}%
    \lhead{\fontsize{8.5pt}{11.5pt}\fontseries{m}\selectfont\MakeUppercase{%
        \documenttitle%
    }}%
}

\begin{document}
    \blinddocument
\end{document}

This is the command line, that I used to generate a pdf file:

% xelatex --shell-escape  rep.tex && open rep.pdf
3
  • 2
    Please provide an MWE (from \documentclass... to \end{document}) that we can compile that shows what you have done and what the problem is. Commented May 25, 2022 at 16:41
  • I will try to provide such a MWE. I though this might already ring a bell to someone. Commented May 25, 2022 at 16:45
  • 1
    I have to see your code, but if you use \pagestyle{plain} instead of \thispagestyle{plain} you may sometimes get this effect (depending on the actual structure of the code). Commented May 25, 2022 at 19:07

2 Answers 2

2
+100

I believe there are two misunderstandings causing you to be confused.

Why is does the page style change when there are several pages?

It is a common typographical convention not to use headers on pages where a chapter starts. This let's the chapter heading be the first thing on the page without capping it with a header (that would usually just contain the chapter heading again).

In order to accommodate for this, LaTeX has the command \thispagestyle which changes the page style for this page only, i.e. it will reset to the default before the next page (as opposed to \pagestyle which changes the page style globally). By default, when you use \chapter, somewhere in the code there is a \thispagestyle{plain} that sets the page style for the page where the chapter starts to plain.

By default, the plain style has the page number in the footer and nothing in the header (this is also the default page style for the whole document). You changed that using fancyhdr which is why you see your custom style on the chapter heading page.

So why does my page style not work on the rest of the document? I changed the default, didn't I?

and here's the second misunderstanding. What \pagestyle{plain} does is not actually telling LaTeX "use the page style plain from now on". Instead, it says "from now on, put the page number in the footer and nothing in the header". That is, it sets the style according to plain, the fact that these settings came from plain is immediately forgotten.

Because of this, just changing the definition of a page style will never take effect in your document, even if you have activated it previously using \pagestyle. It only takes effect when you activate it again. In your example, this is done for the first page by \chapter (using \thispagestyle{plain}) but not for any other pages. That is why the default definitions are still in effect for those pages.

What all this means is that all you have to do to get what you expect is say

\pagestyle{plain}

after your \fancypagestyle definition. This will activate the settings you just defined and make them the document default.

1
  • Thanks a lot for this very helpful answer. The solution works like a charm! Commented Jun 1, 2022 at 7:10
2

First problem: Header and footer disappearing on next page.

The footer is already there, it just falls off the page. It can be corrected by changing the top margin from 2cm to 1cm: \setlength{\topmargin}{1.0cm}

(using \usepackage{showframe} to show the margins)

Before

a

Using \setlength{\topmargin}{1.0cm}

b

Headings

The class report provides three styles empty, plain and headings.

The plain is used on the first page of the chapter and also as the default style for the other pages if headings was not invoked.

Invoke the latter using \pagestyle{headings} in the preamble. Otherwise, the plain style will be applied to the following pages.

Having no header on the first page of a chapter is a typographical convention for books. I use headers on each page of a report with the institution's logo and address.

x

Using fancyhdr

You define \fancypagestyle{plain} to be used in the first page of a chapter, then you need to (a) define \fancypagestyle{fancy} to replace the default style headings and (b) invoke the style fancy with \pagestyle{fancy} (or use \pagestyle{plain} to reproduce the style of the first page of a chapter).

y

This is the final code.

% !TeX TS-program = xelatex

\documentclass[a4paper]{report}

\usepackage{titling}

\title{Test}
\author{Me}
\date{\today}
\let\documenttitle\thetitle

\usepackage[T1]{fontenc}

\usepackage{titlesec}
\usepackage{fancyhdr}
\usepackage{blindtext}

\setlength{\voffset}{-2.540cm}
\setlength{\hoffset}{-2.540cm}

\setlength{\topmargin}{1.0cm}% changed <<<<<<<<<<<<<<<<<
\setlength{\headsep}{1cm}
\setlength{\headheight}{0.5cm}

\setlength{\oddsidemargin}{2.5cm}
\setlength{\footskip}{2.9cm}

\setlength{\textheight}{23.5cm}
\setlength{\textwidth}{16.0cm}

\setlength{\marginparwidth}{0cm}
\setlength{\marginparpush}{0cm}
\setlength{\marginparsep}{0cm}

\fancypagestyle{plain}{%
    \fancyhf{}% 
    \rhead{\fontsize{8.5pt}{11.5pt}\fontseries{m}\selectfont\thepage/X}%
    \lhead{\fontsize{8.5pt}{11.5pt}\fontseries{m}\selectfont\MakeUppercase{%
            \documenttitle%
    }}%
}
\fancypagestyle{fancy}{% added <<<<<<<<<<
    \fancyhf{}% 
    \rhead{\fontsize{8.5pt}{11.5pt}\fontseries{m}\selectfont\thepage/X}%
    \lhead{\fontsize{8.5pt}{11.5pt}\fontseries{m}\selectfont\MakeUppercase{%
            \documenttitle~~\rightmark% % changed <<<<<<<<<<<<<<<<
    }}%
}

\pagestyle{fancy}% added <<<<<<<<<<

\begin{document}
    \blinddocument
\end{document}
1
  • Thank you very much for this very helpful answer! Commented Jun 1, 2022 at 7:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .