[Tex/LaTex] Creating a custom copy of pagestyle plain with fancyhdr

fancyhdrpdfpages

Consider this MWE (compiles with pdflatex -shell-escape test.tex):

\documentclass{book}
\usepackage{filecontents}
\begin{filecontents*}{insert.tex}
  \documentclass{article}
  \usepackage{lipsum}
  \begin{document}
  \thispagestyle{empty}
  \lipsum[1-2]
  \end{document}
\end{filecontents*}

\usepackage{pdfpages}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{} %delete everything
\renewcommand{\headrulewidth}{0pt} %remove the horizontal line in the header
\fancyhead[RE]{\small\nouppercase\leftmark} %even page - chapter title
\fancyhead[LO]{\small\nouppercase\rightmark} %uneven page - section title
\fancyfoot[CE,CO]{AX-\thepage} %page number on all pages

\immediate\write18{pdflatex insert.tex} % compile this, to insert as pdf

\begin{document}

\chapter{Test chapter}
\thispagestyle{fancy}
\section{Test section}

So, blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah ...

\clearpage

\includepdf[pages=-,pagecommand=\thispagestyle{plain}]{insert.pdf}

\end{document}

Here, the first page outputs "AX-1" as pagenumber; but the included pdf shows just "2", because I use pagecommand=\thispagestyle{plain}.

I would like to have page number "AX-2" on the second page too – but if I use pagecommand=\thispagestyle{fancy}, while I get "AX-2" there, I also get the section header which I don't want.

What I'd want ideally is to make a "copy" of the plain pagestyle, say named as plainB, and only redefine \fancyfoot[CE,CO]{AX-\thepage} for it; so I could use it as pagecommand=\thispagestyle{plainB} and have only the customized page number "AX-2" output.

Is this possible at all to do – and if it is, how can I do it?

Best Answer

You can define a new page style. For example:

\fancypagestyle{customplain}{%
\fancyhf{}%
\fancyhf[cf]{<whatever>}%
\renewcommand*\headrulewidth{0pt}}

and then use it as you wish.