Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have a problem with my header and my footer.

If I do that:

\pagestyle{fancy}
\fancyhf{}
\fancyhead[R]{\includegraphics[width=8cm]{img/header.png}}
\fancyfoot[L]{ Name Firstname - v1.0 \\  Date}}
\fancyfoot[R]{\thepage\  / \pageref{LastPage}}

Only the first page from a chapter uses this header and footer.

And if I do that:

\fancypagestyle{plain}
{    
    \fancyhf{}
    \fancyhead[R]{\includegraphics[width=8cm]{img/header.png}}
    \fancyfoot[L]{ Name Firstname - v1.0 \\  Date}}
    \fancyfoot[R]{\thepage\  / \pageref{LastPage}}
}

Other page from a chapter uses this header and footer, but not the first.

How can I set that is the same for both?

Obviously if I put the two codes together, it's work, but I think it's heavy and not optimal...

edit :

I just tested this code (after i read the comment from Werner)

\pagestyle{fancyplain}
\fancyhf{}
\fancyhead[R]{\includegraphics[width=8cm]{img/header.png}}
\fancyfoot[L]{ Name Firstname - v1.0 \\  Date}}
\fancyfoot[R]{\thepage\  / \pageref{LastPage}}

It's work for every page from a chapter, its fine !

But now i have a problem with my table of contents.

\tableofcontents{\thispagestyle{empty}}

This code product a table of content with my fancy header and footer. Strangely, the second page from my table of content is whiteout header and footer (as i want for my entire table).

share|improve this question
1  
which documentclass do you use? –  Micha Apr 19 '13 at 19:10
    
I use the document class report. –  Karim Apr 19 '13 at 19:13
add comment

1 Answer 1

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 \chapters.

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.
share|improve this answer
    
Thank you for your help. Your solution work for my chapters. But i have always a problem with my table of content. The first page is whiteout header and footer (empty), but the second page have the fancy header and footer (plain). But, if a use this : \tableofcontents{\thispagestyle{empty}} It's work, my entire table is empty. So...i think my problem is solved. –  Karim Apr 20 '13 at 12:34
    
@Karim: Yes, adding \thispagestyle{empty} after \tableofcontents would make the final page before the next chapter empty. Indeed it may be required and seem clumsy in your code, but be necessary to make it work. –  Werner Apr 20 '13 at 14:46
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.