2

this may or may not seem to be a weird thing to want, but I would like to have a customized header on all my pages, except the first one of each chapter, ToC, ..... Furthermore, I would like to have a footer in form of a simple line above the page number on each and every page, even on the first page of a chapter, ToC, ...

Well, me being new to LaTeX, I was thinking it could work if I insert the \fancypagestyle{plain} command after the header, so it might not apply for the header but for the footer. Well, that did not work.

Does anyone know how to do that? Is it even possible?

Thank you so much for any advice in advance!

\documentclass[10pt,a4paper, twoside]{report}
\usepackage[latin1]{inputenc}
\usepackage{fancyhdr}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\pagestyle{fancy}

\begin{document}
\lhead[Contents]{\includegraphics[height=22pt]{Figures/WHM.eps}}
\rhead[{\includegraphics[height=22pt]{Figures/WHM.eps}}]{Contents}
\fancypagestyle{plain}{
\renewcommand{\footrulewidth}{0.4pt}}
\tableofcontents
\end{document}
6
  • The starting page of chapter are plain, meaning an empty head (default). You can customize your headers and footers with the modern and flexible scrlayer-scrpage or fancyhdr.
    – Johannes_B
    Commented Aug 21, 2014 at 7:51
  • Hey Johannes, thank you so much for your help. Actually I thought I was using the fancyhdr? Didn't I? In previous papers I simply needed a header on each page except the chapter page and I did that with \thispagestyle{fancy}. Now I need a footer, too. But in contrast to the header, I want it on all pages.
    – Nadine
    Commented Aug 21, 2014 at 8:01
  • Yes you do, but i gave you an alternative as well. But right now, i am not quite sure, what you are trying to achieve. nor what the question is. But it is possible.
    – Johannes_B
    Commented Aug 21, 2014 at 8:02
  • Okay, now I understand. Do you have a solution for how to achieve it with fancyhdr? I have never used scrlayer-scrpage before, but I will try to figure out how to use it!
    – Nadine
    Commented Aug 21, 2014 at 8:04
  • We can get a solution, but i need to know what should be in the header an where. In your example above, you explicitely put stuff on plain pages.
    – Johannes_B
    Commented Aug 21, 2014 at 8:08

2 Answers 2

1

I am not entirely sure that I understand what you want but the code below:

  • has a page footer on EVERY page with a line and the page number on the right-hand side
  • has your page headers except on the "first" pages

Rather than using fancyhdr etc I define the page headers and footers directly. When you type \pagestyle{mine} what happens is that latex executes the command \ps@mine, if it exists. The actual page headers and footers are stored in \@oddhead, \@evenhead, \@oddfoot and \@evenfoot so you just need to set these appropriately. There is also a \ps@empty command for clearing all of the current page headers and footers.

Anyway, this is what I have done:

\documentclass[10pt,a4paper,twoside]{report}
\usepackage{mwe}
\usepackage{tcolorbox}
\usepackage[foot=4em]{geometry}% need to make the footer bigger

\makeatletter
\def\my@foot{\hbox to \textwidth{\rlap{\rule[2ex]{\textwidth}{0.4pt}}\hfill\thepage}}
\def\ps@mine{\ps@empty% clear all current headings and footings
    \let\@oddfoot\my@foot\let\@evenfoot\my@foot
    \def\@oddhead{Contents\hfill\includegraphics[height=22pt]{example-image-a}}
    \def\@evenhead{\includegraphics[height=22pt]{example-image-a}\hfill Contents}
}
\def\ps@plain{% this seems to be the "first" page for report.cls
    \ps@empty\let\@oddfoot\my@foot\let\@evenfoot\my@foot
}
\makeatother
\pagestyle{mine}

\begin{document}
  \tableofcontents
  \section{A}\lipsum \section{B}\lipsum \section{C}\lipsum \section{D}\lipsum
\end{document}

Perhaps the most painful part of this game is working out which pagestyle controls the first pages of chapters etc. For report.cls this seems to be \ps@plain, so I have changed it in order to get your line in the footer on the "first" pages as well. (For amsart and friends I think it is \ps@firstpage...).

If this isn't quite what you want then please explain clearly what the problems are and I will try and fine-tune.

6
  • I hope you saw the comment under my answer ;-)
    – Johannes_B
    Commented Aug 21, 2014 at 14:07
  • @Johannes_B Ah, I think I misunderstood the nature of your challenge:) Having just looked at how your answer works I'm unsure why the OP didn't run with your first solution. I should also try and understand what this KOMA package does sometime...it looks interesting.
    – user30471
    Commented Aug 21, 2014 at 14:15
  • I would feel really sorry if your efforts were in vain.
    – Johannes_B
    Commented Aug 21, 2014 at 14:20
  • Hey guys, again thank you so much for your time and helpful suggestions. @Andrew's version was just perfect, but for some reason it shattered my thesis into million pieces when applied it. But it is no big deal since I have a backup of my thesis. I decided to just leave it as it is know, meaning no header and footer on the chapter pages. I am way to unexperienced in latex to fix it and I gave you guys a headache and caused a lot of confusion as well. This was not my intention, so I am really sorry for that.
    – Nadine
    Commented Aug 21, 2014 at 15:26
  • This answer is the handmade version, my answer (or rather comment) provides solutions used by many people. It should have worked out of the box. Please make sure you read some basic introductory material. It should cover this as well. Learning something new always requires to know the basics.
    – Johannes_B
    Commented Aug 21, 2014 at 17:49
2

Too long for a comment:

I still don't know, what you want in your headers. You used Contents, so i guess you want the \headmark. There is absolutely no reason to set this by hand.

An alternative to fancyhdr would be using the moden package scrlayer-scrpage. And why not use the corresponding KOMA class?

\documentclass[10pt,a4paper, twoside]{scrreprt}
\usepackage[automark,footsepline,plainfootsepline]{scrlayer-scrpage}
\usepackage{graphicx}
\pagestyle{scrheadings}
\clearscrheadfoot
\ihead{\includegraphics[height=22pt]{example-image-1x1}}
\ohead{\headmark}
\cfoot[\pagemark]{\pagemark}
\usepackage{blindtext}
%\usepackage{showframe}
\begin{document}
\tableofcontents
\blinddocument
\blinddocument
\blinddocument
\blinddocument
\blinddocument
\blinddocument
\end{document}

The solution using fancyhdr.

\documentclass[10pt,a4paper, twoside]{report}
\usepackage{fancyhdr}
\usepackage[demo]{graphicx}
\pagestyle{fancy}
\lhead{\includegraphics[height=22pt]{Figures/WHM.eps}}
\rhead{\rightmark}
\addtolength{\headheight}{1.2\baselineskip}
\fancypagestyle{plain}{%
    \fancyhf{}%
    \fancyfoot[C]{\thepage}%
\renewcommand{\headrulewidth}{0.0pt}
\renewcommand{\footrulewidth}{0.4pt}}
\usepackage{blindtext}
\usepackage{showframe}
\begin{document}
\tableofcontents
\blinddocument
\end{document}
2
  • Hey Johannes, thank you so much for taking the time and making the effort to help me with this problem, but your solution just does not work for me. I tried to adjust your code, but I am obviously way to unexperienced with latex and so I can't do it. I'll try to find another way. :-)
    – Nadine
    Commented Aug 21, 2014 at 8:58
  • I'd really like to help you, but you are giving me no information on where you are stuck.
    – Johannes_B
    Commented Aug 21, 2014 at 8:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .