0

When I compile the following code, there's no page number after the first page. If I comment out the Geometry command at the top of the code, the page number appears well beyond the printable page.

What's happening to all the pages after the title page once I try to ad an image in the header of the first page only?

\documentclass[11pt]{article}

\usepackage{fancyhdr}
\usepackage{lastpage}
\usepackage{graphicx}
\usepackage{lipsum}
\usepackage{caption}
\usepackage[margin=3cm]{geometry}

\pagestyle{fancy}
\fancypagestyle{newstyle}{%
  \fancyhf{}% Clear header/footer
    \fancyfoot[C]{Page \thepage \hspace{1pt} of \pageref{LastPage}}
    \rhead{\includegraphics[width=6cm]{banner}}
}

\pagestyle{newstyle}

\begin{document}


\maketitle
\thispagestyle{newstyle}
\lipsum[1-2]

\newpage

\lipsum[1-2]


\end{document}
  • Off topic: replace \thepage \hspace{1pt} of by \thepage\ of – Sigur Feb 6 '15 at 18:03
  • Move \pagestyle{newstyle} inside the document environment. – Sigur Feb 6 '15 at 18:04
  • Use \usepackage[margin=3cm,showframe]{geometry} to see the space reserved for the header and you will find out that it could be too shorter to fit the image inside it. – Sigur Feb 6 '15 at 18:07
1
  1. To use \maketitle you have to define on preamble at least \title{} or \author{}.

  2. Load the package geometry with the showframeoption so you can have total control of margins configuration.

\usepackage[margin=3cm,showframe]{geometry}

  1. Since you are inserting an image in the header you will have to adjust the header's height with the option head= within geometry.

  2. Finally, call your page style as \begin{document}\pagestyle{newstyle}.

MWE

\documentclass[11pt]{article}

\usepackage{fancyhdr}
\usepackage{lastpage}
\usepackage{graphicx}
\usepackage{lipsum}
\usepackage{caption}
\usepackage[margin=3cm,showframe,head=8mm,a5paper]{geometry} % a5paper just for demo

\fancypagestyle{newstyle}{%
    \fancyhf{}% Clear header/footer
    \fancyfoot[C]{Page \thepage\ of \pageref{LastPage}}
    \rhead{\includegraphics[width=6cm,height=5mm]{example-image-a}}
}

\title{title}

\begin{document}
\pagestyle{newstyle}

\maketitle
\lipsum[2]

\newpage    
\lipsum[1-2]

\end{document}

enter image description here

ps: note that \maketitle does not use your page style, it uses the plain one.

| improve this answer | |

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.