[Tex/LaTex] Using titlesec to have \chaptertitle and \sectiontitle in twosided report

double-sidedfancyhdrheader-footertitlesec

I would like to customize the headers of my report. These should contain chaptertitle and sectiontitle. From here:

Header not displaying correctly on chapter page due to subsection

I have made an working MWE using fancyhdr{}

\documentclass[10pt,twoside]{report}
\usepackage{blindtext}
\usepackage{fancyhdr}
\pagestyle{fancy}

\renewcommand{\chaptermark}[1]{% 
\markboth{#1}{}} 

% Allows calling chapter and section names in headers and footers.
\renewcommand{\chaptermark}[1]{%
 \markboth{#1}
  {\noexpand\firstsectiontitle}}
\renewcommand{\sectionmark}[1]{}
\renewcommand{\sectionmark}[1]{%
  \markright{#1}\gdef\firstsectiontitle{#1}}
\newcommand\firstsectiontitle{}

% General Header and Footer
\fancyhf{}
\fancyhead[LE]{\leftmark \space - \space \rightmark}
\fancyhead[RO]{\rightmark \space - \space \leftmark}
\fancyfoot[LE]{\thepage}
\fancyfoot[RO]{\thepage}

% Chapter Header and Footer
\fancypagestyle{plain}{%
\fancyhf{}
\fancyhead[LE]{\leftmark \space - \space \rightmark}
\fancyhead[RO]{\rightmark \space - \space \leftmark}
\fancyfoot[LE]{\thepage}
\fancyfoot[RO]{\thepage}
}

%DOCUMENT
\begin{document}

\chapter{First chapter}
\section{First section}
\blindtext[6]
\pagebreak
\section{Second section}
\blindtext[6]
\pagebreak
\chapter{Second chapter}
\section{First section}
\blindtext[4]
\pagebreak
\section{Second section}
\blindtext[4]

\end{document}

As I am using titlesec anyhow, I was wondering if I could achieve something similar. With great help from here:
How do I make a subsection title visible in a header on page with chapter / section
I have done this:

\documentclass[10pt,twoside]{report}
%\documentclass[10pt]{report}
\usepackage[a4paper]{geometry}
\usepackage{blindtext}
\usepackage{ifthen}
\usepackage[pagestyles,extramarks]{titlesec}

\settitlemarks*{chapter,section}

\newpagestyle{mystyle}{
\sethead
    [\chaptertitle\ifthesection{\ --\ \firstextramarks{section}\sectiontitle}{}]
    [][]
    {}{}
    {\chaptertitle\ifthesection{\ --\ \firstextramarks{section}\sectiontitle}{}}
\setfoot[\thepage][][]{}{}{\thepage}
}
\pagestyle{mystyle}
\assignpagestyle{\chapter}{mystyle}

\begin{document}

\chapter{First chapter}
\section{First section}
\blindtext[6]
\pagebreak
\section{Second section}
\blindtext[6]
\pagebreak
\chapter{Second chapter}
\section{First section}
\blindtext[4]
\pagebreak
\section{Second section}
\blindtext[4]

\end{document}

Using the default (onesided) layout works fine. When I move over to the twosided layout however, the section name is not displayed on the chapter page. I could not find anything in the titlesec documentations, so my questions are:

  • Does it make sense trying to avoid fancyhdr{} for the sake of simplicity?
  • If it does, how can I display the section name?

Thanks in advance!

Best Answer

You need the outermarks option, not extramarks. And the code you have could but produce the same order of titles on every page.

Here is a code that works, that I made as simple as possible:

\documentclass[twoside]{report}%
\usepackage[utf8]{inputenc}
\usepackage{fourier, heuristica}
\usepackage[a4paper]{geometry}
\usepackage{blindtext}

\usepackage[pagestyles, outermarks]{titlesec}

\newpagestyle{mystyle}{
\sethead
    [\chaptertitle\ifthesection{~--~\sectiontitle}{}][][]
    {}{}{\ifthesection{\sectiontitle~--~}{}\chaptertitle}
\setfoot[\thepage][][]{}{}{\thepage}
}
\pagestyle{mystyle}
\assignpagestyle{\chapter}{mystyle}

\begin{document}

\chapter{First chapter}
\section{First section}
\blindtext[6]
\pagebreak
\section{Second section}
\blindtext[6]
\pagebreak

\chapter{Second chapter}
\section{First section}
\blindtext[4]
\pagebreak
\section{Second section}
\blindtext[4]

\end{document} 

And the first two resulting pages:

enter image description here

enter image description here