4

I am having some issues with fancyhdr setting my \headheight. The package seems to add too much \headheight. This is my current set up:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage{textcomp}
\usepackage{lastpage}
\usepackage[includeheadfoot,margin=0.3in,headheight=54pt,landscape]{geometry}
\usepackage{longtable}
\usepackage{tabu}
\usepackage{fancyhdr}
\usepackage{ragged2e}

\setlength{\parindent}{0pt}
\fancypagestyle{header}{ 
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\setlength{\headheight}{54pt}
\fancyhead{}
\fancyfoot{}
\fancyhead[C]{
\begin{minipage}[t][20pt]{\textwidth}
\flushleft
\begin{minipage}[t]{0.33\textwidth}
\flushleft
Print date: 2016{-}Jun{-}21 11:57:51
\newline 
R1023
\end{minipage}
\begin{minipage}[t]{0.33\textwidth}
\centering
Company Name
\end{minipage}
\begin{minipage}[t]{0.33\textwidth}
\flushright
Page \thepage\ of \pageref{LastPage}
\end{minipage}
\end{minipage}
\begin{minipage}[t]{\textwidth}
\centering
\begin{Large}\textbf{Title}\end{Large}
\linebreak 
\begin{large}Subtitle\end{large}
\flushleft{\begin{small}More Text\end{small}}
\end{minipage}
}
\fancyfoot[C]{ 
}
}
\pagestyle{header}

\begin{document}
Page 1
\newpage
Page 2
\end{document}

As you can see the \headheight on the first page is as set by geometry: 54pt, but on the second page the fancyhdr package resets it to ~70pt resulting in a lot of empty space left on the page. Is there something I am missing in the header that is increasing the size?

Werner
  • 603,163
Vlad G
  • 43

1 Answers1

1

Your main problem stems from an incorrect headheight setting. One can either remove the headheight setting from geometry's options and see what fancyhdr suggests in the .log, or set the header in a box and measure it yourself (remember to consider both the height and the depth of this box). The former is much easier.

The following construction is a little easier on the eyes and uses some automation for coming up with the time and date (using datetime2):

enter image description here

\documentclass{article}

\usepackage{lastpage}
\usepackage[includeheadfoot,margin=0.3in,headheight=74pt,headsep=0pt,landscape]{geometry}
\usepackage{fancyhdr,tabularx}
\usepackage[english]{datetime2}

\DTMnewdatestyle{dashdate}{%
  \renewcommand{\DTMdisplaydate}[4]{\number##1-\DTMenglishshortmonthname{##2}-\number##3}%
  \renewcommand{\DTMDisplaydate}{\DTMdisplaydate}%
}
\DTMsetdatestyle{dashdate}
\DTMsettimestyle{default}

\fancypagestyle{header}{
  \renewcommand{\headrulewidth}{0pt}
  \renewcommand{\footrulewidth}{0pt}
  \fancyhf{}
  \fancyhead[L]{%
    \begin{tabularx}{\textwidth}{@{}X>{\centering\arraybackslash}X>{\raggedleft\arraybackslash}X@{}}
      Print date: \DTMtoday~\DTMcurrenttime & % http://tex.stackexchange.com/q/994/5764
      Company Name &
      Page \thepage~of~\pageref{LastPage} \\
      R1023 \\
      & \Large\bfseries Title \\
      & \large Subtitle \\
      \\
      \small More text
    \end{tabularx}% 
  }
}
\pagestyle{header}

\begin{document}

Page 1

\newpage
Page 2

\end{document}

The 74pt height for the header stems from what is printed in the .log without it:

Package Fancyhdr Warning: \headheight is too small (12.0pt):
Make it at least 73.60002pt.
We now make it that large for the rest of the document.
This may cause the page layout to be inconsistent, however.

Werner
  • 603,163
  • Hmm, interesting. I was under the impression that an \fbox surrounded both the height and the depth of its content. But when I add showframe to the geometry package the header goes beyond both of the boxes. – Vlad G Jun 21 '16 at 20:55
  • \fbox should, but remember that \fbox sets a box with a gap of \fboxsep between the content and the rule around it. If your header fits exactly, the box will run over the margins. – Werner Jun 21 '16 at 20:58