[Tex/LaTex] Suppress headers when page contains a section title using titlesec

header-footersectioningsections-paragraphstitlesec

I'm writing a book with titlesec and try to suppress headers containing the section name, when the section starts at the top of the respective page. Given that all my sections start on a new page I tried \assignpagestyle, but it doesn't work. Manually adding \thispagestyle for each section works, but there should be a better solution.

\documentclass[a4paper,12pt]{book}

\usepackage[pagestyles]{titlesec}

\renewpagestyle{headings}{%
  \sethead[\chaptertitle][][]
      {}{}{\thesection~\sectiontitle}%
  \setfoot{}{\thepage}{}%
}
\renewpagestyle{plain}{%
  \setfoot{}{\thepage}{}%
}
\pagestyle{headings}
\newpagestyle{section}{%
  \sethead[\chaptertitle][][]
      {}{}{}%
  \setfoot{}{\thepage}{}%
}
\assignpagestyle{\section}{section}

\begin{document}

\chapter{header ok}
\clearpage

\section{First}     % warning here
even page
\clearpage

\section{Second}    % warning here
suppress header here, odd page, start section on top
\clearpage
chapter headers are ok, even page
\clearpage
keep header here, odd page, no new section

\end{document}

Using MikTeX 2.8 I get the following warnings:

Package titlesec Warning: Page style in straigh class ignored on input line <XXX>

Best Answer

Add the following to your preamble:

\usepackage{xpatch}
\xpretocmd{\section}{\thispagestyle{plain}}{}{}

Or should you want to suppress headers only for odd pages containing section titles:

\usepackage{xpatch}
\usepackage{scrextend}
\xpretocmd{\section}{\ifthispageodd{\thispagestyle{plain}}{}}{}{}
Related Question