4

after getting the constant warning I shouldn't use fancyhdr with KOMA I decided to switch to scrlayer-scrpage. Unfortunately I can't get it to work despite of reading through the documentation.

This is what I have at the moment

\documentclass[12pt,ngerman]{scrreprt}
\renewcommand{\familydefault}{\sfdefault}
\usepackage[ansinew]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{geometry}
\geometry{verbose,tmargin=2cm,bmargin=3.5cm,lmargin=3cm,rmargin=2.5cm}
\usepackage{graphicx}
\usepackage{fancyhdr}
\pagestyle{fancy}
\lhead{\slshape \leftmark}
\chead{}
\rhead{{\includegraphics[height=1cm]{IMG/Logo.JPG}}}
\lfoot{}
\cfoot{}
\rfoot{\thepage}
\usepackage{color}
\definecolor{mygreen}{RGB}{23,156,125}
\renewcommand{\footrule}{\vbox to 0pt{\hbox to \headwidth{{\color{mygreen}\hrulefill}}}\vss}
\renewcommand{\headrule}{\vbox to 0pt{\hbox to \headwidth{{\color{mygreen}\hrulefill}}}\vss}
\begin{document}
    Hello
\end{document}

The result is the chapter title in the upper left corner, a logo in the upper right corner, page number in the lower right corner and two green vertical lines.

I would like to have the same output with scrlayer-scrpage with two small changes. First I would like to reduce the spacing between the line and the chapter title. Second I would like to align the chapter title to the bottom border of the image.

Any help would be very much appreciated. Thanks in advance

Jon

************** EDIT ******************************************************

Thanks to cfr this is what I got now

\documentclass[12pt,headsepline,footsepline,plainfootsepline,plainheadsepline]{scrreprt}
\renewcommand{\familydefault}{\sfdefault}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{geometry}
 \geometry{verbose,tmargin=3.5cm,bmargin=3.5cm,lmargin=3cm,rmargin=2.5cm,headheight=33pt}
\usepackage{graphicx}
\usepackage{xcolor,calc}
\definecolor{mygreen}{RGB}{23,156,125}
\usepackage{scrlayer-scrpage}
\usepackage{kantlipsum}
\setkomafont{pageheadfoot}{\upshape}
\setkomafont{pagehead}{\slshape}
\setkomafont{headsepline}{\color{mygreen}}
\setkomafont{footsepline}{\color{mygreen}}
\pagestyle{scrheadings}
\automark{chapter}
\ihead{\leftmark\hfill \includegraphics[height=1cm]{IMG/Logo.jpg}}
\ohead{}
\chead{}
\ofoot*{\thepage}
\cfoot*{}
\chead{}
\ihead*{\leftmark\hfill \includegraphics[height=1cm]{IMG/Logo.jpg}}

\begin{document}
    Hello
    \part{Hello}
    \chapter{Some chapter}
    \kant[1-10]
\end{document}

Thanks again for that. This is (after some minor changes) exactly what I wanted. But I have two follow up questions. How would I proceed when I wanted to alter the header style for certain pages (e.g. two images in the top header instead of one)? Furthermore a change from geometry to typearea was suggested. How would you incorporate this package with the current settings?

Thank again

2
  • What did you try? That still uses fancyhdr. – cfr Jul 27 '15 at 23:00
  • What chapter title? – cfr Jul 28 '15 at 0:32
8

This translates your page layout into KOMA's terms. It may not make the requested changes because I don't know what they are meant to be. Your example does not include any chapters, let alone chapter titles, and it is impossible to guess which distance you are talking about or what is meant to align with what.

Note that, as originally configured, your layout will be inconsistent because both fancyhdr and scrlayer-scrpage will adjust headheight as required, changing the page dimensions in unpredictable ways. To avoid this, you need to make the height at least 33pt and to tell geometry about it.

Note also that scrlayer-scrpage is designed to cooperate with typearea. By using geometry, you lose the advantages of this. Consider whether you could use KOMA's typearea instead.

Here's the initial translation:

\documentclass[12pt,headsepline,footsepline]{scrreprt}
\renewcommand{\familydefault}{\sfdefault}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{geometry}% do you really need this? Better to use KOMA's setup if possible
\geometry{verbose,tmargin=2cm,bmargin=3.5cm,lmargin=3cm,rmargin=2.5cm,headheight=33pt}% the value 33pt is obtained from console warnings output by scrlayer-scrpage - this is the minimum required value, given the inclusion of the graphic - again, it would be better if you could use typearea for this
\usepackage[demo]{graphicx}
\usepackage{xcolor}
\definecolor{mygreen}{RGB}{23,156,125}
\usepackage{scrlayer-scrpage}
\setkomafont{pageheadfoot}{\upshape}
\setkomafont{pagehead}{\slshape}
\setkomafont{headsepline}{\color{mygreen}}
\setkomafont{footsepline}{\color{mygreen}}
\pagestyle{scrheadings}
\automark{chapter}
\ihead{\leftmark}
\ohead{\includegraphics[height=1cm]{IMG/Logo.JPG}}
\ofoot{\thepage}
\cfoot{}
\chead{}

\begin{document}
    Hello
\end{document}

initial results

I am guessing that you want the same footer on plain pages as on other pages. This can be achieved using the starred versions of \cfoot and \ofoot, and adding plainfootsepline to the class options:

\documentclass[12pt,headsepline,footsepline,plainfootsepline]{scrreprt}
\renewcommand{\familydefault}{\sfdefault}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{geometry}% do you really need this? Better to use KOMA's setup if possible
\geometry{verbose,tmargin=2cm,bmargin=3.5cm,lmargin=3cm,rmargin=2.5cm,headheight=33pt}% the value 33pt is obtained from console warnings output by scrlayer-scrpage - this is the minimum required value, given the inclusion of the graphic - again, it would be better if you could use typearea for this
\usepackage[demo]{graphicx}
\usepackage{xcolor}
\definecolor{mygreen}{RGB}{23,156,125}
\usepackage{scrlayer-scrpage,kantlipsum}
\setkomafont{pageheadfoot}{\upshape}
\setkomafont{pagehead}{\slshape}
\setkomafont{headsepline}{\color{mygreen}}
\setkomafont{footsepline}{\color{mygreen}}
\pagestyle{scrheadings}
\automark{chapter}
\ihead{\leftmark}
\ohead{\includegraphics[height=1cm]{IMG/Logo.JPG}}
\ofoot*{\thepage}
\cfoot*{}
\chead{}
\begin{document}
    Hello
    \chapter{Some chapter}
    \kant[1-10]
\end{document}

modified results

I'm guessing that the further change you want concerns the alignment of the \leftmark in the header. I'm not sure how this constitutes 2 changes, mind, since aligning with the bottom of the image will also reduce the distance....

So, I'm guessing you want something like this:

target

In which case, it is easiest, I think, to simply define the header in one go, setting the other parts of the header empty:

\documentclass[12pt,headsepline,footsepline,plainfootsepline]{scrreprt}
\renewcommand{\familydefault}{\sfdefault}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{geometry}% do you really need this? Better to use KOMA's setup if possible
\geometry{verbose,tmargin=2cm,bmargin=3.5cm,lmargin=3cm,rmargin=2.5cm,headheight=33pt}% the value 33pt is obtained from console warnings output by scrlayer-scrpage - this is the minimum required value, given the inclusion of the graphic - again, it would be better if you could use typearea for this
\usepackage{graphicx}
\usepackage{xcolor,calc}
\definecolor{mygreen}{RGB}{23,156,125}
\usepackage[markcase=upper]{scrlayer-scrpage}
\usepackage{kantlipsum}
\setkomafont{pageheadfoot}{\upshape}
\setkomafont{pagehead}{\slshape}
\setkomafont{headsepline}{\color{mygreen}}
\setkomafont{footsepline}{\color{mygreen}}
\pagestyle{scrheadings}
\automark{chapter}
\ihead{\leftmark\hfill \includegraphics[height=1cm]{example-image-a}}
\ohead{}
\chead{}
\ofoot*{\thepage}
\cfoot*{}
\chead{}
\begin{document}
    Hello
    \chapter{Some chapter}
    \kant[1-10]
\end{document}

EDIT

In response to the question concerning changing the headers, you can simply redefine \ihead (or \ihead*) as you wish. Do note, however, that doing so is likely to be confusing to readers. The point of running heads is that they contain information which is consistent throughout the document (except on special pages such as the first pages of chapters etc.). Also, the headers should not distract from the body of the document.

\ihead{\includegraphics[height=1cm]{example-image-b}\hfill\includegraphics[height=1cm]{example-image-a}}
\kant[11-14]
\ihead{\leftmark\hfill \includegraphics[height=1cm]{example-image-a}}
\kant[15-20]

modified headers

EDIT EDIT

You can produce roughly the same page layout using typearea by commenting out the calls to geometry and adding

\areaset[5mm]{155mm}{272mm}

modified area

However, if you are stuck with a requirement to use precisely the dimensions given, then you may need to stick to geometry even though it does not cooperate with KOMA. You need to be a bit more careful to make sure you specify adequate headheight etc. in that case.

2
  • Wow. Incredible answer and almost what I wanted. Thank you very much. If it's not to much to ask there are two follow up questions to this (see edit of original post). I will mark this as the correct answer then. – JonBlumfeld Jul 28 '15 at 5:46
  • @JonBlumfeld I've added a couple of edits. – cfr Jul 28 '15 at 12:40

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.