# How to repeat code on every page from the second one?

I want to repeat certain code block on every page on top starting from second page. This is assuming that header is defined. There is a package that can detect the number of page?

Thanks

• Do you just need a way to determine the current page number? Some answers to that is available tex.stackexchange.com/questions/11962/… If the answers there do not address your question, please edit your question to give more details. – Willie Wong Dec 2 '19 at 16:33
• Finding out the page number is not that difficult, but requires either using \labels, or tapping into the shipout routine (through page styles or otherwise). Can you be a bit more specific about your needs? – Werner Dec 2 '19 at 17:58

Use two pagestyles called, for example first and main. Then in your document do something along the lines:

\documentclass...
% define the first and main pagestyles, or use existing ones
%   ...
\pagestyle{main}
\begin{document}
% some text (which might set its own page style)
\thispagestyle{first} % for the first page
% more text on the first page then \pagestyle{main} comes into effect on the following pages

• Sorry about my ignorance, but there is a way to define new pagestyles without overwriting fancyhdr pagestyles? – benjujo Dec 2 '19 at 20:58
• @benjujo Yes. fancyhdr lets you define as many pagestyles as you want. Please read the manual (> texdoc fancyhdr). It is up to you not to overwrite any predefined styles. – Peter Wilson Dec 3 '19 at 18:45