I want to have unumbered chapters/sections appearing in the headers, so I used titlesec and defined a pagestyle that only displays the chapter/section title in the left/right marks. Now, I want that numbered chapters show as "Chapter X. Chapter title", for sections it would be "X.Y Section title". For unumbered it would be just "Chapter title" and "Section title".
My solution is to edit the \chaptermark
and the \sectionmark
like this :
\titleformat{\chapter}[display]
{\chaptermark{This is a test \thechapter. #1}\bfseries \Huge}
{\chaptertitlename \hspace{0ex} \thechapter}
{2ex}
{#1}
It works for chapters, unumbered chapters, unumbered sections but not for sections
MWE :
\documentclass{book}
\usepackage[pagestyles,explicit]{titlesec}
\newpagestyle{myps}[\scshape]{%
\sethead[\footnotesize \oldstylenums{\thepage}][][\chaptertitle]% even
{\sectiontitle}{}{\footnotesize \oldstylenums{\thepage}} % odd
}
\titleformat{name=\chapter , numberless}
{\chaptermark{#1}\normalfont\bfseries\Huge \filcenter}
{}
{0pt}
{#1}
\titleformat{\chapter}[display]
{\chaptermark{This is a test \thechapter. #1}\bfseries \Huge}
{\chaptertitlename \hspace{0ex} \thechapter}
{2ex}
{#1}
\titleformat{\section}
{\sectionmark{This is a test \thesection #1} \Large \bfseries \filcenter}
{\thesection}
{0.7em}
{#1}
\titleformat{name=\section , numberless}
{\sectionmark{#1} \Large \bfseries \filcenter}
{}
{0.7em}
{#1}
\begin{document}
\pagestyle{myps}
\chapter{Chapter title}
\section{Section title}
test
\newpage
test
\newpage
test
\end{document}
The issue :
because the following code is not functionnal
\titleformat{\section}
{\sectionmark{This is a test \thesection #1} \Large \bfseries \filcenter}
{\thesection}
{0.7em}
{#1}
meanwhile all the others are functionnal.
\section*
?