titlesec footers and headers

I've read through the titlesec package, and I don't understand why my headers don't appear (in chapters, not TOC or intro) and why the page numbers on the first page of each chapter are in the center and not on the right.

MWE:

\documentclass{book}
\usepackage{lipsum}

\usepackage[compact,pagestyles]{titlesec}
\usepackage{titletoc}

%page numbering and headers
\newpagestyle{mystyle}{
\setfoot[\thepage][][]{}{}{\thepage}
\sethead[\chaptertitle][][]{}{}{\chaptertitle}
}
\pagestyle{mystyle}
%

%creates the chapter heading style
\titleformat{\chapter}[display]
{\normalfont\huge\filcenter\bfseries\rmfamily}
{\titlerule[1pt]%
\vspace{2pt}%
\titlerule
\vspace{1pc}%
\LARGE\MakeUppercase{\chaptertitlename} \thechapter}
{1pc}
{\titlerule[1pt]
\vspace{0.5pc}%
\huge\bfseries\rmfamily}
%

%to get rid of headers on blank page after clelardoublepage
%https://tex.stackexchange.com/a/323284/121944
\makeatletter
\def\cleardoublepage{%
\clearpage\if@twoside \ifodd\c@page\else%
\setlength{\columnseprule}{0pt}\thispagestyle{empty}\hbox{}\newpage\setlength{\columnseprule}{1pt}%
\if@twocolumn\setlength{\columnseprule}{0pt}\hbox{}\newpage\setlength{\columnseprule}{1pt}\fi%
\fi\fi%
}
\makeatother

\begin{document}

\cleardoublepage
\pagenumbering{gobble}
\tableofcontents

\frontmatter
\chapter{Introduction}

\mainmatter
\chapter{}
\lipsum[1-10]
\chapter{}
\lipsum[11-20]
\end{document}


1 Answer

Here is a solution (hopefully): I define a mystylefrontand a mystylemain pagestyles, for frontmatter and mainmatter. The first style displays the chapter title in the header, and the second displays \chaptertitlename \thechapter, followed by the chapter title if there's any. The code can easily be simplified if no chapter in mainmatter has a title.

Note that, for empty pages, you don't have to patch whatever: simply load the option [clearempty]. If you want empty pages to have a page number printed, remove this option.

\documentclass{book}
\usepackage{lipsum}

\usepackage[pagestyles]{titlesec}
\usepackage{titletoc}
%page numbering and headers
\newpagestyle{mystylefront}{ % for frontmatter
\setfoot[\thepage][][]{}{}{\thepage}
\sethead[\chaptertitle][][]{}{}{\chaptertitle}
}
\newpagestyle{mystylemain}{ % for mainmatter
\setfoot[\thepage][][]{}{}{\thepage}
\sethead[\chaptertitlename\,\thechapter~\chaptertitle][][]{}{}{\chaptertitlename\,\thechapter~\chaptertitle}
}
\renewpagestyle{plain}{%
\sethead{}{}{}
\setfoot[\thepage][][]{}{}{\thepage}
}

%creates the chapter heading style
\titleformat{\chapter}[display]
{\normalfont\huge\filcenter\bfseries\rmfamily}
{\titlerule[1pt]%
\vspace{2pt}%
\titlerule
\vspace{1pc}%
\LARGE\MakeUppercase{\chaptertitlename} \thechapter}
{1pc}
{\titlerule[1pt]
\vspace{0.5pc}%
\huge\bfseries\rmfamily}

\begin{document}

\pagestyle{empty}
\tableofcontents%
\thispagestyle{empty}

\frontmatter
\pagestyle{mystylefront}
\chapter{Introduction}
\lipsum[1-5]
\mainmatter
\pagestyle{mystylemain}
\chapter{}
\lipsum[1-10]
\chapter{}
\lipsum[11-20]

\end{document}


• Looks promising, but a couple little issues. 1.) contents appears in both the header and footer, on the page of the contents. Don't need it to appear at all; 2.) I would like the page number to appear on the blank page in between chapters. – AML Apr 11 '18 at 19:42
• I added \pagestyle{empty} right before \tableofcontents and that seemed to do the trick for issue #1. – AML Apr 12 '18 at 13:03
• Actually, let's ignore problem #2. If you edit your answer to include the fix to issue #1 then I will accept your answer. – AML Apr 12 '18 at 13:35
• @AML: I've added a slightly different code to have no header/footer in the table of contents. As to issue #2, simply remove the clearempty option. Unless you want only the page number (i.e. a plain style) in ‘empty’ pages? – Bernard Apr 12 '18 at 18:11