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).
Best Answer
You need to set the page style to
plain
after redefining it usingfancyhdr
's\fancypagestyle{plain}{...}
command. This is described in thefancyhdr
documentation (section 7 Redefiningplain
style, p 7-8):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 usingor
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
(fromreport.cls
- your document class):Note that
\tableofcontents
executes\chapter*
, which in itself initiates a page break via\clearpage
(or\cleardoublepage
, depending on your document class options, likeopenright
). 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 anetoolbox
patch (there are other ways as well):Taking all of this into consideration, you might be after the following setup:
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:
\makeatletter
and\makeatother
do?etoolbox
documentation regarding command patching via\patchcmd
(section 3.4 Patching, p 11)Some other things to consider:
\linewidth
if you wish to have a header image that spans the entire width of the text block (rather than8cm
).pageslts
package which provides aVeryLastPage
label, depending on whether or not you have unprocessed floats at the end of your report.