LaTeX forum ⇒ Page LayoutMultiple pagestyles in one document Topic is solved

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
ispacewalker
Posts: 2
Joined: Sat Sep 04, 2021 9:43 am

Multiple pagestyles in one document

Postby ispacewalker » Sat Sep 04, 2021 10:13 am

When multiple \pagestyle in one document, the page styles become quite strange. How can I make the first work until the second, the 2nd until the 3rd, and so on? Please run the following code to view the effect.

\documentclass{report}

\begin{document}

\newcommand*{\name}{plain}
\pagestyle{\name}
\chapter{\name}
Some stuff.
\newpage
{\Huge \name}

\renewcommand*{\name}{headings}
\pagestyle{\name}
\chapter{\name}
Some stuff.
\newpage
{\Huge \name}

\renewcommand*{\name}{empty}
\pagestyle{\name}
\chapter{\name}
Some stuff.
\newpage
{\Huge \name}
\end{document}

Bartman
Posts: 240
Joined: Fri Jan 03, 2020 2:39 pm

Postby Bartman » Sat Sep 04, 2021 2:03 pm

In this one-sided document, insert the \clearpage command before changing the page style, so that the changed style will only take effect from the new chapter.

Since the page style of the first page of each chapter is set to plain, the style selected by pagestyle is not set until the second chapter page.

A suggestion:

\documentclass{report}
\usepackage{etoolbox}

\newcommand*{\name}{plain}
% If the selected style should also apply to the first chapter page.
%\patchcmd{\chapter}{plain}{\name}{}{}
% or
%\patchcmd{\chapter}{\thispagestyle{plain}}{}{}{}

\begin{document}
\pagestyle{\name}
\chapter{\name}
Some stuff.
\newpage
{\Huge \name}

\clearpage% added
\renewcommand*{\name}{headings}
\pagestyle{\name}
\chapter{\name}
Some stuff.
\newpage
{\Huge \name}

\clearpage% added
\renewcommand*{\name}{empty}
\pagestyle{\name}
\chapter{\name}
Some stuff.
\newpage
{\Huge \name}
\end{document}


If I am right with my assumption concerning the first chapter page, it should work even much shorter:

\documentclass{report}
\usepackage{etoolbox}

\newcommand*{\name}{plain}
% If the selected style should also apply to the first chapter page.
\patchcmd{\chapter}{\thispagestyle{plain}}{\pagestyle{\name}}{}{}

\begin{document}
\pagestyle{\name}
\chapter{\name}
Some stuff.
\newpage
{\Huge \name}

\renewcommand*{\name}{headings}
\chapter{\name}
Some stuff.
\newpage
{\Huge \name}

\renewcommand*{\name}{empty}
\chapter{\name}
Some stuff.
\newpage
{\Huge \name}
\end{document}


The source code I replaced can be found in the report.cls file.

ispacewalker
Posts: 2
Joined: Sat Sep 04, 2021 9:43 am

Postby ispacewalker » Sun Sep 05, 2021 4:32 am

Thank you very much! This problem had stressed me out for days.


Return to “Page Layout”

Who is online

Users browsing this forum: No registered users and 3 guests