You need to set the page style to plain
after redefining it using fancyhdr
's \fancypagestyle{plain}{...}
command. This is described in the fancyhdr
documentation (section 7 Redefining plain
style, p 7-8):
\usepackage{fancyhdr,graphicx,lastpage}% http://ctan.org/pkg/{fancyhdr,graphicx,lastpage}
\fancypagestyle{plain}{
\fancyhf{}% Clear header/footer
\fancyhead[R]{\includegraphics[width=\linewidth,height=5pt]{example-image-a}}% Right header
\fancyfoot[L]{Name Firstname - v1.0 \\ Date}% Left footer
\fancyfoot[R]{\thepage\ / \pageref{LastPage}}% Right footer
}
\pagestyle{plain}% Set page style to plain.
This should set the page style to plain
for the entire document, including the first page of \chapter
s.
If you wish to have certain chapters to have a different (empty
, say) page style, you would have to set this manually. For the \tableofcontents
though, this is a bit tricky, since using
\thispagestyle{empty}\tableofcontents
or
\tableofcontents\thispagestyle{empty}
would set it to empty
either too early, or perhaps too late, depending on the choice. This is because of the construction of the command \tableofcontents
(from report.cls
- your document class):
\newcommand\tableofcontents{%
\if@twocolumn
\@restonecoltrue\onecolumn
\else
\@restonecolfalse
\fi
\chapter*{\contentsname
\@mkboth{%
\MakeUppercase\contentsname}{\MakeUppercase\contentsname}}%
\@starttoc{toc}%
\if@restonecol\twocolumn\fi
}
Note that \tableofcontents
executes \chapter*
, which in itself initiates a page break via \clearpage
(or \cleardoublepage
, depending on your document class options, like openright
). So one would have to insert the page style somewhere around the place where the ToC is being built... in this case, at \@starttoc{toc}
. You can do this with an etoolbox
patch (there are other ways as well):
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\makeatletter
\patchcmd{\tableofcontents}% <cmd>
{\@starttoc}% <search>
{\thispagestyle{empty}\@starttoc}
{}{}% <success><failure>
\makeatother
Taking all of this into consideration, you might be after the following setup:
\documentclass[twoside,openright]{report}
\usepackage{fancyhdr,lipsum}% http://ctan.org/pkg/{fancyhdr,lipsum}
\usepackage{graphicx,lastpage}% http://ctan.org/pkg/{graphicx,lastpage}
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\fancypagestyle{plain}{
\fancyhf{}% Clear header/footer
\fancyhead[R]{\includegraphics[width=\linewidth,height=5pt]{example-image-a.pdf}}% Right header
\fancyfoot[L]{Name Firstname - v1.0 \\ Date}% Left footer
\fancyfoot[R]{\thepage\ / \pageref{LastPage}}% Right footer
}
\pagestyle{plain}
\makeatletter
\patchcmd{\tableofcontents}% <cmd>
{\@starttoc}% <search>
{\thispagestyle{empty}\@starttoc}
{}{}% <success><failure>
\makeatother
\begin{document}
\tableofcontents
\chapter{A chapter}\lipsum[1-5]
\end{document}
Of course, this could be changed (even improved) if you don't have a title, or if there was more information on your document structure.
Some references regarding the above usages:
Some other things to consider:
- Using
\linewidth
if you wish to have a header image that spans the entire width of the text block (rather than 8cm
).
- Using the
pageslts
package which provides a VeryLastPage
label, depending on whether or not you have unprocessed floats at the end of your report.
If you don't set a proper head height, fancyhdr
reports the following:
Package Fancyhdr Warning: \headheight is too small (XX.Xpt):
Make it at least YY.YYYYpt.
We now make it that large for the rest of the document.
This may cause the page layout to be inconsistent, however.
As such, the newly-set \headheight
will be the same throughout the document. To avoid this, I've created the following minimal document that sets a consistent head height, adding a vertical space (gap) on the first page to simulate a larger header:
\documentclass{article}
\usepackage{fancyhdr,datetime,geometry,lipsum,graphicx}
%%%%%%%%%%%%%%%%%%date in format Sunday, October 25, 2011
\usdate
\def\theday {\dayofweekname{\day}{\month}{\year}}
\def\mydate {\theday , \today}
%%%%%%%%%%return address%%%%%%%%%%
\def\myname {Frank Thorne}
\def\mydeptname {Department of Mathematics}
\def\myaffiliation {University of South Carolina}
\def\mystreet {1523 Greene Street}
\def\mycitystatezip {Columbia,~SC \quad 29208}
\def\myphone {\textit{Phone:} (803)404-4057 (home)}
\def\office {(803)777-4224}
\def\fax {\textit{Fax:}(803)777-3783}
\def\email {thorne@math.sc.edu}
\def\url {\texttt{http://www.math.sc.edu/~thornef}} % NOTE: use $\sim$ for tilde
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%margins%%%%%%%%%%%%%%%%%%
\geometry{
margin = 1in,
headheight = 13.5pt
}
\setlength{\parindent}{0pt} %controls how the indentation of new paragraphs behaves
\setlength{\parskip}{6pt} %controls the space between paragraphs
%%%%%%%%%%%%%%%%letterhead%%%%%%%%%%%%%%%%
\fancyfoot{}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\pagestyle{fancy}%
\fancypagestyle{firstpage}{
\fancyhf{}% Clear header/footer
%%%usc logo
\fancyhead[L]{\raisebox{\dimexpr-\height+\baselineskip}[0pt][0pt]{\includegraphics[width=2.5in]{example-image}}}
%%%%%%%%%%return address on right%%%%%%%
\fancyhead[R]{\leavevmode\footnotesize\itshape%
\begin{tabular}[t]{l@{}}
\myname \\ \mydeptname \\
\myaffiliation \\ \mystreet \\
\mycitystatezip \\ \email \\[\normalbaselineskip]
\mydate
\end{tabular}}
}
\begin{document}
\thispagestyle{firstpage}
\vspace*{8\baselineskip}
\lipsum[1-10]
\bigskip
\hspace{.5\textwidth}%
\begin{tabular}{@{}l}
Sincerely, \\[2\normalbaselineskip]
Frank Thorne \\
\textit{Assistant Professor of Mathematics}
\end{tabular}
\end{document}
I've used geometry
to adjust the page layout - it's just easier/more convenient.
Best Answer
When you compile your code, you get this warning:
Hence you have to give proper
headheight
and better way of doing this is throughgeometry
package:For your case, ideal will be to use