Using fancyhdr
package, this is what I do for each of my starred sections to print them at the header, e.g.:
\chapter*{{Foreword}} \markboth{{Foreword}}{Foreword}
and this what I have in the relative sections of my preamble:
\fancyhead[RE,RO]{\normalfont\scriptsize\thepage}
\fancyhead[LE]{\sffamily\small {My Book}
\fancyhead[LO]{\sffamily\small\\leftmark}
\fancyfoot{}
How can I automate it so that I do not have to do it manually for each starred section?
With my (very) limited knowledge, I tried,
\renewcommand{\chaptermark}[1]{%
\markboth{#1}{}}
From the fancyhr
package manual, but it didn't work.
MWE: (Exported from LyX):
\documentclass[english]{book}
\usepackage{fontspec}
\setmainfont[Mapping=tex-text]{Minion Pro}
\setsansfont[Mapping=tex-text]{ITC Goudy Sans Std Book}
\usepackage[paperwidth=32pc,paperheight=48pc]{geometry}
\geometry{verbose,tmargin=9pc,bmargin=6pc,lmargin=5pc,rmargin=5pc}
\usepackage{fancyhdr}
\pagestyle{fancy}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}
\usepackage{array}
\makeatletter
\usepackage{enumitem}
\usepackage{yfonts,color}
\usepackage{xcolor}
\usepackage{colortbl}
\arrayrulecolor{lightgray}
\usepackage{titlesec}
\makeatletter
\@addtoreset{footnote}{section}
\makeatother
\renewcommand{\thechapter}{\Roman{chapter}}
\titleformat{\chapter}[display]
{\normalfont\scshape\normalsize\filcenter}
{\normalsize\MakeUppercase{\thechapter} }
{0pt}
{\vspace{1pt}%
\normalsize}
\titlespacing{\chapter}{0pt}{20pt}{80pt}
\titleformat{\section}
{\itshape\normalsize\filright}
{\MakeUppercase{\thesection.}}{.5em}{}
\titlespacing*{\section}{0pt}{60pt}{60pt}
\fancyhead[RE,RO]{\normalfont\scriptsize\thepage}
\fancyhead[LE]{\sffamily\small {My Book}
\fancyhead[LO]{\sffamily\small\\leftmark}
\fancyfoot{}
\makeatletter
\renewcommand*{\cleardoublepage}{\clearpage\if@twoside \ifodd\c@page\else
\hbox{}%
\thispagestyle{empty}%
\newpage%
\if@twocolumn\hbox{}\newpage\fi\fi\fi}
\makeatother
Best Answer
You can add
\markboth
to thenumberless
version of\chapter
. I reorganized the call to packages and the settings. Removekantlipsum
at the end that's only used for generating mock text in the example.Note that
emptypage
avoids the redefinition of\cleardoublepage
by hand.This doesn't spare you from issuing
\addcontentsline
if you need the table of contents.I'll show only page 3 which has the required header.