3

I would like to insert the chapter number and name on the left header of a page. So far, I have used the following code, which works very well:


\renewcommand{\chaptermark}[1]{\markright{\thechapter\;\; #1}{}}

\lhead[\fancyplain{}{}]{\fancyplain{}{\bfseries\rightmark}}

\chead[\fancyplain{}{}]{\fancyplain{}{}}

\rhead[\fancyplain{}{}]{\fancyplain{}{\bfseries\thepage}}

However, if I happen to include sections, this code does not work anymore, replacing the chapter number and name by the section number and name (capitalised, for some reason).

Could anybody please help? Thanks.

1 Answer 1

4
\documentclass{book}
\usepackage[a6paper]{geometry}% just for the example
\usepackage{fancyhdr}
\usepackage{lipsum}

\pagestyle{fancy}
\renewcommand\chaptermark[1]{\markboth{\thechapter\ #1}{}}
\fancyhf{}
\fancyhead[L]{\bfseries\leftmark}
\fancyhead[R]{\bfseries\thepage}
\renewcommand\headrulewidth{0pt}% suppress the header rule

\begin{document}

\chapter{A test chaper}
\section{A test section}
\lipsum[1-5]

\end{document}

The result:

enter image description here

You must log in to answer this question.