0

I have provided a minimal working example in the following, where I couldn't implement the change of colour of headers such as chapter or section depending on whether the page is odd or even.

\documentclass[
  11pt,% default
  a4paper,% default
  titlepage,
  toc=listof,
  toc=bibliography,
  headings=standardclasses,
  headings=big,% default
  chapterprefix=true,
  numbers=noenddot,
  twoside=semi,
]{scrreport}

\usepackage{lipsum}
\usepackage{xcolor}


\usepackage[
  automark,
  headsepline=2pt,
  footsepline=2pt
]{scrlayer-scrpage}% sets pagestyle scrheadings automatically

\clearpairofpagestyles
\ohead{\pagemark}
\ihead{\headmark}
\addtokomafont{pagehead}{\normalfont\large\scshape}
\setkomafont{pagenumber}{}
\usepackage{svg}
\KOMAoptions{
  onpsevenpage={\colorlet{headsepline}{blue}},
  onpsevenpage={\colorlet{footsepline}{blue}},
  onpsoddpage={\colorlet{headsepline}{green}},
  onpsoddpage={\colorlet{footsepline}{green}}
}
\addtokomafont{headsepline}{\color{headsepline}}
\addtokomafont{footsepline}{\color{footsepline}}

\begin{document}
\chapter{Foo}
\section{Bar}
\lipsum[1-20]
\end{document}

1 Answer 1

1

Welcome to TeX.SX! I am unsure whether this is what you are actually aiming for, but if you want to change the color of the font in the page headers in the same way you already change the color of the lines in the page headers and footers, then you can do the following:

\documentclass[
  11pt,% default
  a4paper,% default
  titlepage,
  toc=listof,
  toc=bibliography,
  headings=standardclasses,
  headings=big,% default
  chapterprefix=true,
  numbers=noenddot,
  twoside=semi,
]{scrreport}

\usepackage{lipsum}
\usepackage{xcolor}

\usepackage[
  automark,
  headsepline=2pt,
  footsepline=2pt
]{scrlayer-scrpage}% sets pagestyle scrheadings automatically

\clearpairofpagestyles
\ohead{\pagemark}
\ihead{\headmark}
\usepackage{svg}
\KOMAoptions{
  onpsevenpage={\colorlet{headsepline}{blue}},
  onpsevenpage={\colorlet{footsepline}{blue}},
  onpsoddpage={\colorlet{headsepline}{green}},
  onpsoddpage={\colorlet{footsepline}{green}}
}
\addtokomafont{headsepline}{\color{headsepline}}
\addtokomafont{footsepline}{\color{footsepline}}
\addtokomafont{pagehead}{\color{headsepline}\normalfont\large\scshape}
\setkomafont{pagenumber}{\color{headsepline}}

\begin{document}
\chapter{Foo}
\section{Bar}
\lipsum[1-20]
\end{document}

enter image description here


Edit:

Since the OP clarified that they don't want the text in the headers to be colored but the chapter and section titles, I'll add some more to this answer.

The first approach would probably be, since you already defined colors depending on whether the page is even or odd, to use this color for the chapter and section titles as well. Alas, this does not work, probably because the color definition takes place after the typesetting of the chapter and section titles.

But the KOMA-classes provide the nice macro \Ifthispageodd which allows you to insert different code depending on whether the current page is even or odd. So, you could do the following:

\documentclass[
  11pt,% default
  a4paper,% default
  titlepage,
  toc=listof,
  toc=bibliography,
  headings=standardclasses,
  headings=big,% default
  chapterprefix=true,
  numbers=noenddot,
  twoside=semi,
]{scrreport}

\usepackage{lipsum}
\usepackage{xcolor}

\usepackage[
  automark,
  headsepline=2pt,
  footsepline=2pt
]{scrlayer-scrpage}% sets pagestyle scrheadings automatically

\clearpairofpagestyles
\ohead{\pagemark}
\ihead{\headmark}
\usepackage{svg}
\addtokomafont{pagehead}{\normalfont\large\scshape}
\setkomafont{pagenumber}{}
\KOMAoptions{
  onpsevenpage={\colorlet{headsepline}{blue}},
  onpsevenpage={\colorlet{footsepline}{blue}},
  onpsoddpage={\colorlet{headsepline}{green}},
  onpsoddpage={\colorlet{footsepline}{green}}
}
\addtokomafont{headsepline}{\color{headsepline}}
\addtokomafont{footsepline}{\color{footsepline}}

\addtokomafont{disposition}{\Ifthispageodd{\color{green}}{\color{blue}}}

\begin{document}
\chapter{Foo}
\section{Bar}
\lipsum[1-5]
\section{Bar}
\lipsum[1-5]
\section{Bar}
\end{document}

\addtokomafont{disposition} styles all sectioning titles (apart from chapter and section, it would style the titles for parts, subsections, paragraphs etc. as well). If you want to style the chapter and/or section titles individually, you can use \addtokomafont{chapter} and/or \addtokomafont{section}.

enter image description here


PS: Sorry, the arrangement of the pages in both example images is obviously wrong. The frist page should actually be an odd page (right page). But then, the images are just there to illustrate the output anyways.

2
  • 1
    This is not what i was looking for, my wording and minimal example are probably misleading. What I wanted to achieve was that \section{x} and \chapter{y} commands translate to coloured text x and y in the pdf depending on whether they get printed on an even or on an odd page (e.g. here green for odd pages and blue for even pages). But anyways thank you!
    – Lagrange
    Jul 15, 2022 at 11:40
  • 1
    To Edit: This was exactly what I was looking for and indeed my first approach was the same thing you described, which didnt work out. Thank you very much for your time and answer - my document finally looks presentable :) !
    – Lagrange
    Jul 15, 2022 at 12:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .