[Tex/LaTex] How to add the current section name to the top

header-footer

I'm trying to get the current section name and to add it to the header at right.

\documentclass[12pt,french]{report}
\renewcommand\chaptername{Chapitre}
\renewcommand\appendixname{Annexe}

\let\@oldmakechapterhead\@makechapterhead
\def\@makechapterhead#1{%
\vspace*{10\p@}%
{\parindent \z@
{\reset@font
\usefont{OT1}{phv}{m}{n}
\LARGE\@chapapp~\thechapter\par\nobreak}%
\par\nobreak
\vspace*{30\p@}
\interlinepenalty\@M
\usefont{OT1}{ptm}{b}{n}
{\raggedright \Huge #1}%
\par\nobreak
\vskip 20\p@
\hrule height 1pt
\par\nobreak
\vskip 45\p@
}}
\rhead{\nouppercase\rightmark}
\begin{document}

\addtocontents{toc}{\protect\thispagestyle{empty}}

\chapter{ABC}

\end{document}

How do I to get the current section name and to put it into that line without adding it to TOC, TO Tables and TO Figures, please?

Best Answer

If I understand you question correctly, you are trying to add a header on content pages without adding the same header to the TOC, LOT, LOF pages.

This is best accomplished with the fancyhdr package, which will make regular pages have a header that you define, while keeping frontmatter pages and other special pages (like first pages of Chapters, for instance) as "plain" style, which simply has a page number at the bottom.

This code gives just that:

\documentclass[12pt,french]{report}
\usepackage{blindtext} % For example

\usepackage{fancyhdr}
\fancyhead{} % Clear the headers
\renewcommand{\headrulewidth}{0pt} % Width of line at top of page
\fancyhead[R]{\slshape\leftmark} % Mark right [R] of page with Chapter name [\leftmark]

\pagestyle{fancy} % Set default style for all content pages (not TOC, etc)

\begin{document}

\tableofcontents

%\chapter{ABC}
\blinddocument

\end{document}

Output:

page1

page2

page3