[Tex/LaTex] Problems double-sided document header

fancyhdrheader-footerkoma-script

I'm having troubles setting the header of a two-sided document. I need only the chapter number (not necessarily) and name in the header at left for even pages and at right for odd pages; I don't want a section title not the word "Chapter" in each page.
So far I've try this with fancyhdr:

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

which gives the correct output of chapter but in left for odds and viceversa, plus it doesn't remove the section header. Also, I try with

\usepackage{fancyhdr}
\pagestyle{fancy}
\lhead[]{\thechapter}
\chead{}[\thechapater]

But this only puts the chapter number and adds a horrible 0 in the pages before contents (declaration, acknowledgements, dedication, etc.). I am using documentclass scrreprt.

Thanks!

Best Answer

It would be better not to use the package fancyhdr with KOMA classes like scrreprt.

One of the dedicated packages scrpage2 or scrpage-scrlayer should be used instead.

In your case, it suffices to load the latter and use the page style scrheadings with the following modifications:

\renewcommand*\chaptermarkformat{\thechapter\autodot\enskip}
\automark[chapter]{chapter}

The first line is to eliminate the word "Chapter" from the header and the latter is to place the chapter mark both in even and odd pages.

If you don't want chapter numbers replace the first line with

\renewcommand*\chaptermarkformat{}

MWE:

\documentclass[twoside,openright,chapterprefix=true]{scrreprt}

\usepackage{lipsum} % only for the example

\usepackage{scrlayer-scrpage}

\renewcommand*\chaptermarkformat{\thechapter\autodot\enskip}
\automark[chapter]{chapter}

\pagestyle{scrheadings}

\begin{document}

\chapter{Test}

\lipsum[1-5]

\section{A section}

\lipsum[1-5]

\end{document}

Output:

enter image description here

If you want the header line load scrlayer-scrpage with the option headsepline:

\usepackage[headsepline]{scrlayer-scrpage}

Instead, if you want to swap the sides where headers are printed, you have to define an own style, like this:

\defpagestyle{mystyle}{%
{\hfill\headmark}{\headmark\hfill}{\hfill}
}{%
{\hfill}{\hfill}{\hfill}
}

and use \pagestyle{mystyle} instead of \pagestyle{scrheadings}.

MWE

\documentclass[twoside,openright,chapterprefix=true]{scrreprt}

\usepackage{lipsum} % only for the example

\usepackage{scrlayer-scrpage}

\renewcommand*\chaptermarkformat{\thechapter\autodot\enskip}
\automark[chapter]{chapter}

\defpagestyle{mystyle}{%
{\hfill\headmark}{\headmark\hfill}{\hfill}
}{%
{\hfill}{\hfill}{\hfill}
}

\pagestyle{mystyle}

\begin{document}

\chapter{Test}

\lipsum[1-5]

\section{A section}

\lipsum[1-5]

\end{document} 

Output:

enter image description here