# How to make a header/footer-template for all classes?

I would like to create many documents that all have the same (and also respectively specific) header and footer, no matter which class they are (all of them probably custom classes). Also, creating the documents shall be generic in the future, that is also why it would be nice to outsource that code.

Currently, I focused on writing a custom .sty file. Is this the right way or do I have to/should I include this in every .cls file? Or is there another way to solve this problem? (Tutorial page or example would also be very appreciated as understanding, for example, the fancyhdr documentation is pure horror for me.)

• I think your title is a little misleading. There are no specific a4-classes. Roughly said, you can nearly set every paper size for every document. – Ruben Sep 12 '17 at 18:20
• You should definitely do this with a custom package and not patch every single .cls file by hand. Your first approach is perfectly fine. – Ruben Sep 12 '17 at 18:21
• Thanks for the answer! It is good to know to be on the right way. Title will be changed, too. ("A4-classes"->"classes") – Dosy Sep 12 '17 at 18:24
• Nice! :) I'll add a quick answer for completeness. – Ruben Sep 12 '17 at 18:32
• A last remark: Maybe add into your title 'a header-footer-template' instead of 'template', so future readers may benefit from your question by finding quicker what they are looking for. – Ruben Sep 12 '17 at 18:43

You're totally on the right track. Normally you would simply write something like:

\documentclass{...}
\usepackage{fancyhdr}
...
\begin{document}
...
\end{document}


If some part of the preamble (in this case \usepackage{fancyhdr}<header/footer setup>) should always be the same you simply abstract it into some file to input, a .sty file - like you are alredy targeted.

However, keep in mind that in a package you're advised to use \RequirePackage instead of \usepackage. The overall look of your package could be:

%%dosyhf.sty'
%%
\NeedsTeXFormat{LaTeX2e}[2008/04/05]
\ProvidesPackage{dosyhf}
[2017/09/12 v1.0 Custom headers and footers for every Dosy document]
\RequirePackage{fancyhdr}
\endinput
%%
%% End of file dosyhf.sty'.


\documentclass{...}
\usepackage{dosyhf}
...
\begin{document}
...
\end{document}


A final remark (as for the comment by @AlanMunn): You should really load only the required packages in such an abstraction.

For further reading about the topic here is a post that treats it in a much more general way.

• +1 I think it's also important to stress that this sort of package should load only the exact packages needed to implement the functionality being offered. It shouldn't load 'all the packages that might come in handy' (as many beginner classes/packages sometimes do.) – Alan Munn Sep 12 '17 at 20:24
• Thanks @AlanMunn! Good idea. I'll add a remark. And i've just spotted your comment to the OP. I will also add a link in my answer as it seems highly relevant. – Ruben Sep 12 '17 at 20:36