5

I made a document with 2 pages and headers:

enter image description here

  1. Can I put "Page 2 of 2" at the top of the 2-nd page, so it was vertically aligned with "Commercial invoice"?
  2. How can I manage the padding between the header and the "text"? Without negative \vspace if possible.

Code:

\documentclass{article}
\usepackage{lastpage}
\usepackage{fancyhdr}
\pagestyle{fancy}
% no line in header area
\renewcommand{\headrulewidth}{0pt}
\setlength{\headheight}{96pt}
\fancyhead[L]{
%Text must be shown only on the 1-st page
  \count0 = \thepage
  \ifnum \count0 = 1
    \begin{center}\Large{\bf{Commercial invoice}}\end{center}
    This invoice must be completed in English
  \fi
  %page number, aligned right on all the pages
  \hfill Page \thepage~of~\pageref{LastPage}
}
%no page number at the bottom
\fancyfoot{}
\begin{document}
text
\clearpage
text
\end{document}

2 Answers 2

4
  1. Yes. See the code below.

  2. You can use the geometry package and its headsep key with an appropriate value:

The code (I only used a5paper for the example):

\documentclass{article}
\usepackage[a5paper,headsep=3mm]{geometry}
\usepackage{lastpage}
\usepackage{fancyhdr}
\pagestyle{fancy}

\renewcommand{\headrulewidth}{0pt}
\setlength{\headheight}{96pt}
\fancyhead[L]{%
  \ifnum\value{page}=1 
    \begin{center}\Large\bfseries Commercial invoice\end{center}
    This invoice must be completed in English\hfill 
    Page \thepage~of~\pageref{LastPage}
  \else
   \begin{center}\hfill Page \thepage~of~\pageref{LastPage}\end{center}
    \hfill\phantom{P}
  \fi
}
\fancyfoot{}
\begin{document}
text
\clearpage
text
\end{document}

enter image description here

2
  • Why does \begin{center} shift it's contents upwards? So we had to put the page number inside it on the 2-nd page?
    – user4035
    May 4, 2013 at 8:20
  • Why do we need \hfill\phantom{P} on the 2-nd page? I tried without it and it worked.
    – user4035
    May 4, 2013 at 9:16
3

Adjust the size of \headsep and possibly of other page parameters. The frames are just to better show alignments.

\documentclass{article}
\usepackage[a5paper,
  headsep=48pt,% adjust this space
  headheight=14pt,% this is mandatory
  includehead,
  showframe,% this is for the example
]{geometry}

\usepackage{lastpage}
\usepackage{fancyhdr}
\pagestyle{fancy}

\renewcommand{\headrulewidth}{0pt}

\newcommand\firstpagehead{%
  \parbox[t][0pt]{\textwidth}{%
    {\centering\Large\bfseries Commercial invoice\par}
    \medskip
    This invoice must be completed in English\hfill
    Page \thepage~of~\pageref{LastPage}}%
}    
\newcommand\otherpagehead{%
  \parbox[t][0pt]{\textwidth}{%
    \raggedleft
    Page \thepage~of~\pageref{LastPage}}%
}
\fancyhead[L]{\ifnum\value{page}=1 \firstpagehead\fi}
\fancyhead[R]{\ifnum\value{page}=1\else \otherpagehead\fi}
\fancyfoot{}

\begin{document}
text
\clearpage
text
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .