1

I am trying to make header and footer using fancyhdr.

Following the manuals available in other question I have defined header and footer in my class file but they are not shown in output file. Could you please advice what am I doing wrong?

My class file looks like this:

    % Definicja klasy
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{KPSEClass}[2016/3/19 KPSE LaTeX class]

% Polskie formatowanie
\usepackage[T1]{fontenc}
\usepackage[polish]{babel}
\usepackage[utf8]{inputenc} 
\frenchspacing
\usepackage{indentfirst} 

% Nagłówek
\usepackage[a4paper,width=150mm,top=25mm,bottom=25mm]{geometry}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\rhead{Share\LaTeX}
\lhead{Guides and tutorials}
\rfoot{Page \thepage}

% Domyślny TPL
\LoadClass[twocolumn]{article}

\RequirePackage{xcolor} % Kolory
\usepackage{mdframed} % Boxy

% Formatowanie tytułu

\renewcommand\@maketitle{%

\hfill

\begin{minipage}{0.95\textwidth}
\vskip 2em
\rule{\linewidth}{0.4pt}
{\LARGE \centering \textbf \@title \par }
\rule{\linewidth}{0.4pt}
\vskip 1 em
{\large \centering \@author \par}
\end{minipage}
\vskip 1em \par
}

and document:

\documentclass{KPSEClass}

\author{Autor}
\title{Testowy artykuł}

\begin{document}
\maketitle
\section{Małe}
Małe\footnote{Nie większe niż bardzo małe} jest piekne.
\end{document}

Output:

Output

  • 1
    You're loading article class inside your own class and a customized \@maketitle. That will use a different pagestyle ('headings', most likely) for the titlepage. The fancy style is applied on the next page(s). (Remove \maketitle for a test and you will see your fancy pagestyle on the first page as well) You should also replace \usepackage in your .cls by \RequirePackage... – user31729 Mar 22 '17 at 19:51
  • Correcting myself: \@maketitle does not apply a pagestyle, it's \maketitle and that uses plain. – user31729 Mar 22 '17 at 20:05
1

Here's a small fix of the .cls file by patching \maketitle to use a \titlepagestyle which is itself some wrapper command which can be redefined to use some other pagestyle. It uses fancy by default.

Now the header and footer settings are applied for the title page (if this is really needed at all...)

    % Definicja klasy
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{KPSEClass}[2016/3/19 KPSE LaTeX class]

% Polskie formatowanie
\RequirePackage[T1]{fontenc}
\RequirePackage[polish]{babel}
\RequirePackage[utf8]{inputenc} 
\frenchspacing
\RequirePackage{indentfirst} 

% Nagłówek
\RequirePackage[a4paper,width=150mm,top=25mm,bottom=25mm]{geometry}
\RequirePackage{fancyhdr}
\RequirePackage{xpatch}


\pagestyle{fancy}
\fancyhf{}
\rhead{Share\LaTeX}
\lhead{Guides and tutorials}
\rfoot{Page \thepage}

% Domyślny TPL
\LoadClass[twocolumn]{article}

\RequirePackage{xcolor} % Kolory
\RequirePackage{mdframed} % Boxy

% Formatowanie tytułu


\newcommand{\titlepagestyle}{fancy}
\xpatchcmd{\maketitle}{\thispagestyle{plain}}{\thispagestyle{\titlepagestyle}}{}{}

\renewcommand\@maketitle{%
\hfill

\begin{minipage}{0.95\textwidth}
\vskip 2em
\rule{\linewidth}{0.4pt}
{\LARGE \centering \textbf \@title \par }
\rule{\linewidth}{0.4pt}
\vskip 1 em
{\large \centering \@author \par}
\end{minipage}
\vskip 1em \par
}

Document .tex

\documentclass{KPSEClass}

\author{Autor}
\title{Testowy artykuł}

\begin{document}
\pagestyle{fancy}
\maketitle
\section{Małe}
Małe\footnote{Nie większe niż bardzo małe} jest piekne.

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.