scrpage2 - Chapter and Section on two lines in header?

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
\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
\deftripstyle{fancy}[0pt][0.4pt]
{\leftmark \newline \rightmark}{}{\thepage}
{Nom du document}{}{Lieu} %page style for right pages (odd)
\pagestyle{fancy}


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
\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:

• Edit : so far your answer is the best to me, because it allows me to have the correct alignement (odd-even dependent) on header, thank. – V.B. Mar 11 '14 at 16:49

You can use a tabular:

\documentclass[twoside,a4paper,11pt]{scrbook}
\usepackage[T1]{fontenc} %encodage police
\usepackage[utf8]{inputenc} %encodage clavier
\usepackage[francais]{babel} %langue
\deftripstyle{fancy}[0pt][0.4pt]
{\begin{tabular}[t]{@{}l@{}}\leftmark \\ \rightmark\end{tabular}}{}{\thepage}
{Nom du document}{}{Lieu} %page style à droite (impair)

\pagestyle{fancy}

\usepackage{kantlipsum}

\begin{document}
\chapter{Un titre}

\section{Encore}

\kant[1-12]

\end{document}


With scrlayer-scrpage a tabular is still better:

\documentclass[twoside,a4paper,11pt]{scrbook}
\usepackage[T1]{fontenc} %encodage police
\usepackage[utf8]{inputenc} %encodage clavier
\usepackage[francais]{babel} %langue
\defpagestyle{fancy}{%
{\thepage\hfill\begin{tabular}[b]{@{}r@{}}\leftmark \\ \rightmark\end{tabular}}
{\begin{tabular}[b]{@{}l@{}}\leftmark \\ \rightmark\end{tabular}\hfill\thepage}
{}
}{%
{Nom du document}{}{Lieu} %page style à droite (impair)
}

\pagestyle{fancy}

\usepackage{kantlipsum}

\begin{document}
\chapter{Un titre}

\section{Encore}

\kant[1-12]

\end{document}


However, I don't see why duplicating information in this way: you'll have the same information in facing pages, in places very near to each other.

• Thanks, but alignement isn't correct on even pages, and if you change it, it won't be correct on odd pages. – V.B. Mar 11 '14 at 16:51
• @V.B. You didn't tell what alignment you want. – egreg Mar 11 '14 at 16:54
• My bad, I assumed it was obvious that I wanted to keep an alignement on the line extremity. – V.B. Mar 11 '14 at 16:58
• @V.B. See my update and the final note. – egreg Mar 11 '14 at 17:05
• Thank you for the update, after all I like it, because using minipage feels like using an unappropriate tool that was design for other purposes (page tool). To respond to your last comment, I would say that this layout was chosen based on 2 rules, I wanted pages number outside top, and I wanted Section/Chapter top, but I will consider changing the layout, maybe Sec/Chap outside top, and page° outside bottom, I don't know yet. The point is now I know how to change it, many thanks. I have 2 other questions, directly related to this context, should I open another topic, or can I ask it there? – V.B. Mar 12 '14 at 11:58

You can place the pair of lines in a \parbox:

\documentclass[twoside,a4paper,11pt,headlines=2.5]{scrbook}

\usepackage[utf8]{inputenc} %encodage clavier
\usepackage[T1]{fontenc} %encodage police

\newcommand{\oddevenlap}[1]{\ifodd\value{page}\rlap{#1}\else\llap{#1}\fi}

\deftripstyle{fancy}[0pt][0.4pt]
{\parbox[b]{0pt}{\strut\oddevenlap{\leftmark}\\
\oddevenlap{\rightmark\strut}}}{}{\thepage}
{Nom du document}{}{Lieu} %page style à droite (impair)

\pagestyle{fancy}

\usepackage{blindtext}

\begin{document}
\blinddocument

\end{document}


Here on even pages (Updated) I have used \llap to put the \leftmark in a box of zero width with the mark sticking out to the left, so that I don't need to decide on a value for the width of the \parbox. The \strut commands give this box uniform height and depth and usual circumstances. I have passed an increased headlines option to the documentclass to help the page layout.

• This works bad in odd pages. – karlkoeller Mar 11 '14 at 16:04
• @karlkoeller Oops - switching now added, many thanks. – Andrew Swann Mar 11 '14 at 16:37