[Tex/LaTex] scrpage2 – Chapter and Section on two lines in header

header-footerkoma-scriptscrpage2

Here is a the beginning of my code :

\documentclass[twoside,a4paper,11pt]{scrbook}
\usepackage[UTF8]{inputenc} %encodage clavier
\usepackage[T1]{fontenc} %encodage police
\usepackage[francais]{babel} %langue
\usepackage{scrpage2} %head-foot koma
\deftripstyle{fancy}[0pt][0.4pt]
          {\leftmark}{}{\thepage}
          {Nom du document}{}{Lieu} %page style for right pages (odd)
\pagestyle{fancy}

…which works like a charm, header/footer respect the twoside option by changing the display on odd/even pages.

Question :
As I have a lot of sections and chapters in my document, and both are useful to situate the page, I'd like to have both of them displayed on the inner header, on 2 lines, how can I do that?

I have tried this: (which doesn't work)

\documentclass[twoside,a4paper,11pt]{scrbook}
\usepackage[UTF8]{inputenc} %encodage clavier
\usepackage[T1]{fontenc} %encodage police
\usepackage[francais]{babel} %langue
\usepackage{scrpage2} %head-foot koma
\deftripstyle{fancy}[0pt][0.4pt]
            {\leftmark \newline \rightmark}{}{\thepage}
            {Nom du document}{}{Lieu} %page style for right pages (odd)
\pagestyle{fancy}

Best Answer

Here is a solution.

First of all, if you have an up-to-date KOMA-script bundle, use scrlayer-scrpage instead of scrpage2.

Instead of using \deftripstyle we will use \defpagestyle:

The line

\setlength{\headheight}{22pt}

is to increase a little the room for the header.

MWE (replace scrlayer-scrpage with scrpage2 if you have an old KOMA/script bundle)

\documentclass[twoside,a4paper,11pt]{scrbook}
\usepackage[utf8]{inputenc} %encodage clavier
\usepackage[T1]{fontenc} %encodage police
\usepackage[francais]{babel} %langue
\usepackage[headsepline,footsepline]{scrlayer-scrpage} %head-foot koma
\setlength{\headheight}{22pt}
\defpagestyle{fancy}{%
  {\thepage\hfill\begin{minipage}[b]{0.8\linewidth}\raggedleft\leftmark \\ \rightmark\end{minipage}}
  {\begin{minipage}[b]{0.8\linewidth}\raggedright\leftmark \\ \rightmark\end{minipage}\hfill\thepage}
  {\hfill}
}{%
  {Lieu\hfill Nom du document}
  {Nom du document\hfill Lieu}
  {\hfill}
}
\pagestyle{fancy}

\usepackage{blindtext} % just for the example

\begin{document}
\blinddocument
\end{document} 

Output:

enter image description here