# Titlesec ignores odd and even page formatting for chapters

I am trying to format the appearance of the chapters depending if they appear on an even or odd page. Based on the documentation of titlesec it should work with the option page=even and page=odd. This works for sections but not for chapters. Here is a MWE:

\documentclass[11pt,twoside]{report}
\usepackage[a4paper]{geometry}
\geometry{a4paper, top=22mm, left=45mm, right=25mm, bottom=30mm}
\usepackage{lipsum}
\usepackage[rigidchapters,explicit]{titlesec}
\titleformat{name=\section,page=odd}{}{ODD:}{.5em}{}
\titleformat{name=\section,page=even}{}{EVEN:}{.5em}{}
\begin{document}
\chapter{ChapterA}
\section{Section a} \lipsum[1-2]
\section{Section b} \lipsum[1-2]
\section{Section c} \lipsum[1-2]
\chapter{ChapterB}
\section{Section a} \lipsum[1-2]
\section{Section b} \lipsum[1-2]
\section{Section c} \lipsum[1-2]
\chapter{ChapterC}
\section{Section a} \lipsum[1-2]
\section{Section b} \lipsum[1-2]
\section{Section c} \lipsum[1-2]
\end{document}


If you replace both \chapter in the titlesec command with \section it works.

Is there a reason for that? How can i use a different \titleformat command for odd and even pages?

• Minority view: Whatever you want to do with titlesec, you can either do more easily without or more easily do without. Majority view: it is the only game in town. ;) – cfr Apr 16 '17 at 2:07

By default, titlesec doesn't act much on the standard way for typesetting chapter titles, that is, it still relies on \@makechapterhead.

You have to redeclare the title class:

\documentclass[11pt,twoside]{report}
\usepackage[a4paper]{geometry}
\geometry{a4paper, top=22mm, left=45mm, right=25mm, bottom=30mm}

\usepackage[rigidchapters]{titlesec}
\usepackage{lipsum}

\titleclass{\chapter}{top}
\titleformat{name=\chapter,page=odd}{}{ODD:}{.5em}{}
\titleformat{name=\chapter,page=even}{}{EVEN:}{.5em}{}

\begin{document}

\chapter{ChapterA}
\section{Section a} \lipsum[1-2]

\chapter{ChapterB}
\section{Section a} \lipsum[1-2]

\end{document}


• Thank you so much! This solved the problem! I still have to research why the line \titleclass{\chapter}{top} made the difference, but it was very simple to use. – Andrei Jun 29 '17 at 11:12

Yes, it seems that the page option doesn't take effect for \chapter.

You can work around this by declaring something like:

\titleformat{name=\chapter}{\Huge}{\ifthenelse{\isodd{\thepage}}{ODD:}{EVEN:}}{.5em}{}


with the help of \ifthenelse from the ifthen package.

MWE:

\documentclass[11pt,twoside]{report}
\usepackage[a4paper]{geometry}
\geometry{a4paper, top=22mm, left=45mm, right=25mm, bottom=30mm}
\usepackage{lipsum}
\usepackage[rigidchapters,explicit]{titlesec}
\usepackage{ifthen}
\titleformat{name=\section,page=odd}{}{ODD:}{.5em}{}
\titleformat{name=\section,page=even}{}{EVEN:}{.5em}{}
\titleformat{name=\chapter}{\Huge}{\ifthenelse{\isodd{\thepage}}{ODD:}{EVEN:}}{.5em}{}

\begin{document}
\chapter{ChapterA}
\section{Section A} \lipsum[1-2]
\chapter{ChapterB}
\section{Section B} \lipsum[1-2]
\chapter{ChapterC}
\section{Section C} \lipsum[1-2]
\end{document}


Output (needs two compilations, at least!)