[Tex/LaTex] Customizing the header with fancyhdr

fancyhdrheader-footerkoma-script

I am writing a report using the scrreprt KOMA class. Currently my header looks like this:

Current header

Introduction is the chapter name.

I would like to make two changes to it:

  1. I would like to have the chapter name on the left of the header and the section name on the right. I have already tried \lhead{\thechapter} but this only gives me the chapter number, not the title.
  2. How can I change the font used in the header to match the one in the figure? It looks like it's the default font for section titles in the KOMA classes, but I'm not 100% sure.
    New header font

Best Answer

Redefine \chaptermark/ \sectionmark to display sectioning number plus title, and redefine \lhead/\rhead to use \leftmark/\rightmark plus the formatting instructions \sffamily\bfseries.

\documentclass{scrreprt}

\usepackage{fancyhdr}
\pagestyle{fancy}

\renewcommand*{\chaptermark}[1]{\markboth{\thechapter.~~#1}{}}
\renewcommand*{\sectionmark}[1]{\markright{\thesection.~~#1}}

\lhead{\sffamily\bfseries \leftmark}
\rhead{\sffamily\bfseries \rightmark}

\usepackage{lipsum}

\begin{document}

\chapter{foo}

\section{foobar}

\lipsum[1-12]

\end{document}​

enter image description here