Page LayoutMultiple pagestyles in one document

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
Post Reply
ispacewalker

Multiple pagestyles in one document

Post by ispacewalker »

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.

Code: Select all

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

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
Bartman
Posts: 366
Joined: Fri Jan 03, 2020 2:39 pm

Multiple pagestyles in one document

Post by Bartman »

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:

Code: Select all

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

Code: Select all

\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

Multiple pagestyles in one document

Post by ispacewalker »

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