5

Using LaTeX, I'm trying to fit into the header a minipage containing the page number above a logo. However,

  1. The minipage is pushed out of the header into the head separation space;
  2. The distance between the page number and the logo varies from page to page.

How do I get it right without using fancyhdr?

Here is the code:

\NeedsTeXFormat{LaTeX2e}[2001/06/01]
\ProvidesClass{blabla}[2012/01/22 v2.0.2 blabla class]
\RequirePackage{geometry}
\RequirePackage{graphicx}
\RequirePackage{float}
\LoadClass[12pt, legalpaper, oneside, final]{article}
\geometry{top=6mm, headheight=40mm, headsep=40mm, total={165mm,243mm}, includeheadfoot}
\AtEndOfClass{\pagestyle{blabla}}

\def\ps@blabla{
\def\@oddhead{
\begin{minipage}{\textwidth}
\vspace{8mm}
\begin{center}
Page \arabic{page}
\end{center}
\vspace{-6mm}
\begin{figure}[H]
\centering
\includegraphics[width=17mm]{logo.png}
\end{figure}
\end{minipage}}

\def\@oddfoot{
\begin{minipage}{\textwidth}
blabla
\end{minipage}}

\def\@evenhead{\@oddhead} \def\@evenfoot{\@oddfoot}}

\endinput

1 Answers1

5

I don't see why using a complicated way, when fancyhdr can do it more easily:

\documentclass{article}
\usepackage{fancyhdr}

\usepackage{geometry}
\usepackage[demo]{graphicx}
\geometry{top=6mm, headheight=40mm, headsep=40mm, total={165mm,243mm}, includeheadfoot}

\pagestyle{fancy}
\renewcommand{\headrulewidth}{0pt}
\fancyhf{}
\fancyhead[L]{%
  \begin{minipage}{\textwidth}
  \vspace{8mm}
  \centering
  Page \arabic{page}\\[6pt]
  \includegraphics[width=17mm,height=17mm]{logo.png}
\end{minipage}}

\fancyfoot[L]{\begin{minipage}{\textwidth}
blabla
\end{minipage}}

\usepackage{kantlipsum}

\begin{document}
\kant
\end{document}

The demo option to graphicx is just for avoiding to have the picture. Note that a figure environment is not necessary for using \includegraphics.

You can fix the height reserved for the header by not setting headheight and letting fancyhdr suggest the suitable value; for example, with this code fancyhdr tells that the height is 86.90962pt, so setting headheight=90pt will be sufficient.

egreg
  • 1,121,712
  • Thank you for the valuable advice concerning the redundancy of a figure environment for using \includegraphics. It seems to me that in fancyhdr one can manage without minipages. – Christopher Jun 02 '12 at 15:23
  • @Christopher It should be pointed out that figure environments are not actually redundant to \includegraphics. @egreg's hint refers to your specific purpose being not a common use case for a float, which is what a figure defines. – dgs Jun 02 '12 at 16:54