It maby be weird, I want to make header and footer for every page including the first page of each chapter, how can I do this?
[Tex/LaTex] header and footer of the first page of every chapter
chaptersheader-footer
Related Solutions
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:
- What do
\makeatletter
and\makeatother
do? etoolbox
documentation regarding command patching via\patchcmd
(section 3.4 Patching, p 11)
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 than8cm
). - Using the
pageslts
package which provides aVeryLastPage
label, depending on whether or not you have unprocessed floats at the end of your report.
The first page of a chapter is typeset using the plain
pagestyle so that it stands out from other pages. You can modify it with something like:
\fancypagestyle{plain}{%
\fancyfoot[LE, RO]{Apurba Paul}
\fancyfoot[LO, RE]{Using fancyhdr}}
to change the style so your footer is also on the first page of a chapter, leaving the default header unchanged.
Best Answer
For example, if you use
fancyhdr
, you could writein your preamble. Then, all first pages of chapters, which would have plain style, would show fancy style. Or use
\fancypagestyle{plain}{}
, see thefancyhdr
manual for this.Or use
\let\ps@plain\ps@headings
instead, or generally use your page style name after\ps@
.\ps@plain
stands for plain page style and can be reassigned this way.