Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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>
share|improve this question
add comment

2 Answers

up vote 8 down vote accepted

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}}{}}{}{}
share|improve this answer
1  
Using \usepackage{xpatch} and \xpretocmd{\section}{\thispagestyle{section}}{}{} is equivalent to your second solution, where the odd/even distinction is made using titletoc in the definition of \newpagestyle{section}. –  Markus Schmassmann Apr 21 '12 at 1:42
add comment

The warning

Package titlesec Warning: Page style in straight class ignored on input line 30

gives you a hint about the problem: the page style you defined for section pages wasn't applied and the reason is that \section is, by default, (using the titlesec terminology) of straight class; i.e., is intended to produce titles in the middle of text. To allow the application of the page style, you can change the class of \section to top:

\titleclass{\section}{top}

This, together with \newcommand\sectionbreak{\clearpage} will give the desired result (the spacing for section titles is corrected using \titlespacing{\section}{0pt}{*-3}{*1.5}):

\documentclass[a4paper,12pt]{book}
\usepackage[pagestyles]{titlesec}

\titleclass\section{top}
\newcommand\sectionbreak{\clearpage}
\titlespacing{\section}{0pt}{*-3}{*1.5}

\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}
share|improve this answer
1  
This will add two pages in the OP's example, as \sections now start on odd pages. –  lockstep Apr 21 '12 at 0:06
    
@lockstep: not necessarily; if the OP uses \sectionbreak to start a new page with \section, then there will be no additional pages. –  Gonzalo Medina Apr 21 '12 at 0:16
    
That's better, but the space above \section is still different from the OP's version. –  lockstep Apr 21 '12 at 0:18
    
@lockstep: true. I've added a comment. –  Gonzalo Medina Apr 21 '12 at 0:21
    
@GonzaloMedina: \titlespacing{\section}{0pt}{*-3}{*1.5} corrects the space above \section, proposed edit of your answer. –  Markus Schmassmann Apr 21 '12 at 1:17
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.