0

I am trying to add a header on the top of each page of my document. I want to have each chapter's name on the left and section name on the right (flushrigt).

\documentclass[12pt, a4paper]{report}

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead[R]{\itshape \nouppercase \rightmark}
\fancyhead[L]{\itshape \nouppercase Chapter \arabic{chapter}}

\setlength{\headheight}{14.5pt}

\begin{document}
\chapter{This is a chapter}
\section{This is a section}
\eject
ABC
\eject
def
\eject
ghi
\end{document}

Also, I want to have the header starting from the first chapter (no header on the list of figures and similar pages), and no chapter name (but a header with 'bibliography') on bibliography pages.

Thank you.

3
  • As for your second thing you wrote, I am quite sure that list of figures pages use the plain page style. So you would need to alter that page style by means of \fancypagestyle{plain}{...}.
    – tush
    Apr 20, 2022 at 20:41
  • 1
    I think that it is more appropriate to ask about it in a different question. I think that you would need to define a new page style, as explained in §12 of the fancyhdr manual, by something like \fancypagestyle{biblio}{\fancyhead[R]{Bibliography}}. Then, before the \printbibliography command, put \pagestyle{biblio}. But I just tried it and apparently it doesn't make any effect, probably because that the first page of the cited works has page style plain, which we never made any change to. So I can't help you more than that.
    – tush
    Apr 20, 2022 at 21:06
  • Thank you very much. The answer below gives me the major part of my question. I avoid adding a header on the bibliography page. I appreciate your help.
    – Lynx
    Apr 20, 2022 at 21:09

1 Answer 1

2

You have to redefine \chaptermark and \sectionmark to use only the chapter/section name.

Also for the second part of the question, start with \pagestyle{plain}, and after the TOC,LOF,LOT use \pagestyle{fancy} (after a \newpage).

\documentclass[12pt, a4paper]{report}

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead[R]{\bfseries \rightmark}
\fancyhead[L]{\bfseries \leftmark}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{#1}}

\setlength{\headheight}{14.5pt}

\begin{document}

\pagestyle{plain}
\tableofcontents
\listoffigures
\listoftables

\newpage
\pagestyle{fancy}
\chapter{This is a chapter}
\section{This is a section}
\newpage
ABC
\newpage
def
\newpage
ghi
\end{document}

enter image description here

5
  • Thank you very much! That's what I indeed needed! How can I make the font bold and not italic?
    – Lynx
    Apr 20, 2022 at 20:46
  • 1
    Use bfseries instead of \itshape. Apr 20, 2022 at 20:47
  • Answer adapted, also added answer to second part of question. Apr 20, 2022 at 20:52
  • On the bibliography page, I see the text "bibliography" on both sides, that is, in the chapter name and section number. I need just one. The others work perfectly.
    – Lynx
    Apr 20, 2022 at 20:59
  • 1
    Just before the bibliography, use \newpage\fancyhead[R]{}. I think this will solve that. Apr 20, 2022 at 21:14

You must log in to answer this question.

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