# Add macro to \chapter command

I am using the report class. And all I want that after the use of \chapter{...} the marco \thispagestyle{onlypagenumber} is added.

I fixed this with just defining a new macro \Chapter{...}

\newcommand{\Chapter}[1]{\chapter{#1}\thispagestyle{onlypagenumber}}

However I would rather like to still use \chapter{...} since people are used to typing \chapter{...} instead of \Chapter{...}. How can I make this small alteration? Note also that \thispagestyle{onlypagenumber} should not be added to star chapters e.g. \chapter*{...}

I tried also using the etoolbox which provides the some of "appto" commands on page 9.

\appto This command appends arbitrary hcodei to a hhooki. If the hcodei contains any parameter characters, they need not be doubled. This command is robust.

This failed however but probably I am doing something wrong. I would prefer a solution of the etoolbox.

Example

\documentclass{book}
\usepackage{fancyhdr}
\usepackage{lipsum}

\fancypagestyle{onlypagenumber}{%
\fancyhf{}
\fancyhfoffset[RO,EL]{2.5cm}
\sffamily
\thepage
}
\sffamily\thepage
}
}

\pagestyle{fancy}
\fancyhf{}
\fancyhfoffset[OR,EL]{2.5cm}
\sffamily\MakeUppercase{\leftmark}
\thepage
}
\sffamily\MakeUppercase{\thepage}
\MakeUppercase{\chaptername}~\thechapter
}
\renewcommand{\chaptermark}[1]{\markboth{\MakeUppercase{#1}}{}}

\newcommand{\Chapter}[1]{\chapter{#1}\thispagestyle{onlypagenumber}}

\begin{document}

\Chapter{Test chapter}
\lipsum[1-40]

\end{document}


An easy way is to patch \chapter:

\usepackage{etoolbox}
\patchcmd{\chapter}{plain}{onlypagenumber}{}{}


because \chapter does \thispagestyle{plain} and the patch will replace plain with onlypagenumber.

However, an easier way is just doing

\fancypagestyle{plain}{%
\fancyhf{}
\fancyhfoffset[RO,EL]{2.5cm}
\sffamily
\thepage
}
\sffamily\thepage
}
}


so as to redefine the plain page style, instead of defining a new one: you probably don't need the plain page style any more, do you?

For changing the style only for numbered chapters, use

\usepackage{etoolbox}

\makeatletter

so that \thispagestyle{plain} issued by \chapter will be countermanded when \@makechapterhead (which is executed only for numbered chapters) is processed.
• If I use the patchcmd it also replaced the page style of chapters with a star (\chapter*{...}) which I do not want. And I cannot use the plain pagestyle since I already have defined that. – WG- May 26 '14 at 10:35