# Using titlesec to have \chaptertitle and \sectiontitle in twosided report

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{}

\fancyhf{}
\fancyfoot[LE]{\thepage}
\fancyfoot[RO]{\thepage}

\fancypagestyle{plain}{%
\fancyhf{}
\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}{
[\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?

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}{
[\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:

• Thank you @Bernard! I did not read about outermarks in the manual. In fact, it is only mentioned once in the examples. In general, do you think makes sense to have as few packages as possible? My intention was to avoid errors caused by interference. Anyhow, thank you for you plain and quick response! You are right, it looks so much simpler now! – lactea Jun 20 '14 at 5:41
• Yes, I try to use as few packages as possible, if they do what I want to do, without having to hack them. A typical example in my opinion is titlesec; I find its companion titleps easier to understand than fancyhdr that I haven't been using for years, and certainly it cooperates well with titlesec. Same remazrk for titletoc, by the way. – Bernard Jun 20 '14 at 7:27
• Thanks for sharing your experiences, @Bernhard. The learning curve is steep, I hope I can keep up to it. Your example made me help understanding TeX better! – lactea Jun 21 '14 at 10:16
• Update: Learned a few lessons. First, all this is mentioned in the titleps(!) document. Second, botmarks did the thing. – lactea Jun 21 '14 at 13:40
• Well, I think outermarks is more sensible in most cases for two-sided printing. – Bernard Jun 21 '14 at 14:44