5

The current section name + chapter.section number is shown in the header. This is normal behaviour (what I want).

Example:

enter image description here

How can I remove the header text, if there is no section on the page. The following example illustrate my problem. The header is "1.0" but I want to show nothing.

Example:

enter image description here

Here my MWE:

\documentclass{scrbook}
\usepackage[english]{babel}
\usepackage{blindtext}

\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{#1}{}}

\fancyhead{}
\fancyhead[LE]{\makebox[2cm][r]{}{}}
\fancyhead[RO]{\rightmark\hspace*{0.2cm}\thesection}


\begin{document}

\chapter{An example chapter}

\blindtext[25]

\section{An example section}

\blindtext
\end{document}
6

Using fancyhdr with scrbook is not recommended. However, here's a solution: issue the \thesection command within \markright. Note that \markright takes only one argument (whereas \markboth needs two).

\documentclass{scrbook}
\usepackage[english]{babel}
\usepackage{lipsum}

\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{%
  \markright{#1\ \thesection}%
}

\fancyhf{}
\fancyhead[RO]{\rightmark}
\fancyfoot[C]{\thepage}

\begin{document}

\chapter{An example chapter}

\lipsum[1-20]

\section{An example section}

\lipsum[1-20]
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.