2

I have a somewhat complex preamble (because of the particular aesthetics I want), due to which I am using scrpage2 package with the book document class. Everything was working fine, until I introduced an unnumbered chapter (the "Introduction"). This resulted in the header of the pages of the introduction to appear as "Contents".

In order to correct that, I resorted to the following fix:

\chapter*{Introduction}
\addcontentsline{toc}{chapter}{Introduction}
\thispagestyle{empty}
\renewcommand*{\chaptermarkformat}{}
\chaptermark{Introduction}
\lipsum[1-20]

This works fine. But I would like to get the chapter numbers back in the header for the rest of my book. Below is an MWE, where I have tried using renewcommand{\chaptermark} to get the chapter numbers back, but after trying out quite a few possible solutions, I still can't get it right ... it just keeps showing the chapter name only.

I want the header for the zero'th chapter to be "Introduction" instead of "Chapter 0: Introduction". But then, how can get Chapter 1: Another Chapter in the header instead of just Another Chapter?

\documentclass[11pt,oneside]{book}

\usepackage{lipsum} % just for testing

%% preamble based on http://www.khirevich.com/latex %%
\usepackage[DIV=14,BCOR=2mm,headinclude=true,footinclude=false]{typearea}
\usepackage[T1]{fontenc}
\usepackage{charter}
\usepackage[expert]{mathdesign}

% Change chapter title font to sans-serif
\usepackage{sectsty}
\chapterfont{\usefont{T1}{qhv}{b}{n}\selectfont\huge}

\usepackage{graphicx}
\usepackage{titlesec}
\usepackage[titles]{tocloft}
\usepackage[activate={true,           % activate protrusion
                      nocompatibility % activate expansion
                     },
            final,                    % enable microtype (disable: "draft")
            tracking=true,            % activate tracking
            kerning=true,             % activate kerning
            spacing=true,             % activate spacing
            factor=1100,              % add 10% to protrusion (default: 1000)
            stretch=10,shrink=10]     % reduce streching/shrinking (default: 20/20)
            {microtype}
\microtypecontext{spacing=nonfrench}
\usepackage[nodayofweek]{datetime}
\usepackage[automark,headsepline,nouppercase]{scrpage2}
\pagestyle{scrheadings}
\clearscrheadings
\automark[chapter]{chapter}
% below, define header for beginning of chapter and "normal" pages
\ohead[\leftmark ~$\vert$ \pagemark]{\leftmark ~$\vert$ \pagemark}
\renewcommand*{\headfont}{}

\DeclareMathVersion{mathchartertext}
\SetSymbolFont{letters}{mathchartertext}{OML}{mdbch}{m}{n}

\titleformat{\section}[hang]
            {\usefont{T1}{bch}{b}{n}\selectfont} % format: \usefont{encoding}{family}{series}{shape}
            {}                                   % label
            {0em}                                % sep between label and title
            {\hspace{-0.4pt}
              \Large \thesection\hspace{0.6em}
            }                                    % before code
            []                                   % after code

\titleformat{\chapter}[display]                       % shape
            {\usefont{T1}{qhv}{b}{n}\selectfont\huge} % format: sans-serif
            {\chaptertitlename\ \thechapter}          % label
            {20pt}                                    % sep
            {\Huge}[\vspace{2ex}\titlerule]           % before code

\begin{document}
\maketitle

\clearpage
\tableofcontents{\thispagestyle{empty}}
\clearpage

\mainmatter
\chapter*{Introduction}
\addcontentsline{toc}{chapter}{Introduction}
\thispagestyle{empty}
\renewcommand*{\chaptermarkformat}{}
\chaptermark{Introduction}
\lipsum[1-20]

\chapter{Another Chapter}
\thispagestyle{empty}
\renewcommand{\chaptermark}[1]{%
    \markboth{Chapter \thechapter{}: #1}{Chapter \thechapter{}: #1}%
}
\lipsum[1-20]

\backmatter

\end{document}

Note: Much of the preamble is not necessary to reproduce the problem I am having. But I included these things in the MWE so that people understand why I am trying to do things this way instead of simply using the scrbook document class from Koma-script.

1
  • You shouldn't use both sectsty and titlesec.
    – egreg
    Sep 4, 2015 at 13:10

2 Answers 2

1

You seem to be wanting continuous numbering across the document (which I like, having roman numbers in the front matter was justified in the olden times, now there's no need for them).

So just redefine \frontmatter and \mainmatter to do what you need.

For having no page number in the chapter starting pages, modify \chapter rather than issuing \thispagestyle{empty} each time (which wouldn't work for \tableofcontents if it needs two or more pages).

Finally, don't load sectsty along with titlesec.

\documentclass[11pt,oneside]{book}

\usepackage{lipsum} % just for testing

%% preamble based on http://www.khirevich.com/latex %%
\usepackage[DIV=14,BCOR=2mm,headinclude=true,footinclude=false]{typearea}
\usepackage[T1]{fontenc}
\usepackage{charter}
\usepackage[expert]{mathdesign}

\usepackage{graphicx}
\usepackage{etoolbox}
\usepackage{titlesec}
\usepackage[titles]{tocloft}
\usepackage[activate={true,           % activate protrusion
                      nocompatibility % activate expansion
                     },
            final,                    % enable microtype (disable: "draft")
            tracking=true,            % activate tracking
            kerning=true,             % activate kerning
            spacing=true,             % activate spacing
            factor=1100,              % add 10% to protrusion (default: 1000)
            stretch=10,shrink=10]     % reduce streching/shrinking (default: 20/20)
            {microtype}
\microtypecontext{spacing=nonfrench}
\usepackage[nodayofweek]{datetime}
\usepackage[automark,headsepline,nouppercase]{scrpage2}
\pagestyle{scrheadings}
\clearscrheadings
\automark[chapter]{chapter}
% below, define header for beginning of chapter and "normal" pages
\ohead[\leftmark ~$\vert$ \pagemark]{\leftmark ~$\vert$ \pagemark}
\renewcommand*{\headfont}{}

\DeclareMathVersion{mathchartertext}
\SetSymbolFont{letters}{mathchartertext}{OML}{mdbch}{m}{n}

\titleformat{\section}[hang]
            {\usefont{T1}{bch}{b}{n}\selectfont} % format: \usefont{encoding}{family}{series}{shape}
            {}                                   % label
            {0em}                                % sep between label and title
            {\hspace{-0.4pt}
              \Large \thesection\hspace{0.6em}
            }                                    % before code
            []                                   % after code

\titleformat{\chapter}[display]                       % shape
            {\usefont{T1}{qhv}{b}{n}\selectfont\huge} % format: sans-serif
            {\chaptertitlename\ \thechapter}          % label
            {20pt}                                    % sep
            {\Huge}[\vspace{2ex}\titlerule]           % before code

\makeatletter
% make \frontmatter and \mainmatter not to reset the numbering
\renewcommand{\frontmatter}{\cleardoublepage\@mainmatterfalse}
\renewcommand{\mainmatter}{\cleardoublepage\@mainmattertrue}

% issue \thispagestyle{empty} instead of \thispagestyle{plain}
% when starting a chapter (needs etoolbox)
\patchcmd{\chapter}{plain}{empty} % empty page style in the chapter starting pages
\makeatother

\begin{document}

\frontmatter

\title{Thesis}
\author{A. Uthor}
\maketitle

\tableofcontents

\chapter{Introduction}
\lipsum[1-20]

\mainmatter

\chapter{Another Chapter}
\lipsum[1-20]

\backmatter

\end{document}

enter image description here

enter image description here

2

To change the layout of the chapter numbers in the header using package scrpage2 or its successor scrlayer-scrpage you can redefine \chaptermarkformat.

Here is a suggestion using scrbook and scrlayer-scrpage (the successor of scrpage2) but without the packages sectsty, titlesec and tocloft.

\documentclass[oneside,
    DIV=14,BCOR=2mm,headinclude=true,footinclude=false,
    chapterprefix
]{scrbook}
\usepackage{lipsum} % just for testing
%% preamble based on http://www.khirevich.com/latex %%
\usepackage[T1]{fontenc}
\usepackage{charter}
\usepackage[expert]{mathdesign}
\DeclareMathVersion{mathchartertext}
\SetSymbolFont{letters}{mathchartertext}{OML}{mdbch}{m}{n}

\usepackage{graphicx}
\usepackage[activate={true,           % activate protrusion
                      nocompatibility % activate expansion
                     },
            final,                    % enable microtype (disable: "draft")
            tracking=true,            % activate tracking
            kerning=true,             % activate kerning
            spacing=true,             % activate spacing
            factor=1100,              % add 10% to protrusion (default: 1000)
            stretch=10,shrink=10]     % reduce streching/shrinking (default: 20/20)
            {microtype}
\microtypecontext{spacing=nonfrench}
\usepackage[nodayofweek]{datetime}

\usepackage[headsepline]{scrlayer-scrpage}
\automark[chapter]{chapter}
\clearpairofpagestyles
\ohead*{\leftmark ~$\vert$ \pagemark}
\renewcommand*{\chaptermarkformat}{\chapapp\ \thechapter:\enskip}
\setkomafont{pagehead}{\normalfont\normalsize\upshape}
\renewcommand\chapterpagestyle{empty}

\setkomafont{disposition}{\usefont{T1}{qhv}{b}{n}\selectfont}

\RedeclareSectionCommand[font=\Large]{section}
\renewcommand\sectionformat{\hspace{-.4pt}\ \thesection\hspace{.6em}}

\RedeclareSectionCommand[
    beforeskip=4.6\baselineskip plus \parskip,
    innerskip=20pt,
    afterskip=2.725\baselineskip plus.115\baselineskip minus .192\baselineskip,
    font=\Huge,
    prefixfont=\huge
]{chapter}
% rule after chapter
\usepackage{etoolbox}
\preto\chapterheadendvskip{%
  {\usekomafont{chapter}\vspace{2ex}\noindent\rule{\textwidth}{.4pt}}\par}

\begin{document}
\title{Title}
\author{Name}
\maketitle
\tableofcontents

\mainmatter
\addchap{Introduction}
\lipsum[1-10]
\chapter{Another Chapter}
\section{A section}
\lipsum[1-20]
\end{document}

Result:

enter image description here


With book, titlesec and scrpage2 you can also redefine \chaptermarkformat to get the desired layout in the Header.

\renewcommand*{\chaptermarkformat}{\chaptername{} \thechapter:\enskip}

To get the unnumbered chapter in the page head use

\chapter*{Introduction}
\markboth{Introduction}{Introduction}

enter image description here

enter image description here

Code:

\documentclass[11pt,oneside]{book}

\usepackage{lipsum} % just for testing

%% preamble based on http://www.khirevich.com/latex %%
\usepackage[DIV=14,BCOR=2mm,headinclude=true,footinclude=false]{typearea}
\usepackage[T1]{fontenc}
\usepackage{charter}
\usepackage[expert]{mathdesign}
\usepackage{graphicx}
\usepackage{titlesec}
\usepackage[titles]{tocloft}
\usepackage[activate={true,           % activate protrusion
                      nocompatibility % activate expansion
                     },
            final,                    % enable microtype (disable: "draft")
            tracking=true,            % activate tracking
            kerning=true,             % activate kerning
            spacing=true,             % activate spacing
            factor=1100,              % add 10% to protrusion (default: 1000)
            stretch=10,shrink=10]     % reduce streching/shrinking (default: 20/20)
            {microtype}
\microtypecontext{spacing=nonfrench}
\usepackage[nodayofweek]{datetime}
\usepackage[automark,headsepline,nouppercase]{scrpage2}
\pagestyle{scrheadings}
\clearscrheadings
\automark[chapter]{chapter}
% below, define header for beginning of chapter and "normal" pages
\ohead[\leftmark ~$\vert$ \pagemark]{\leftmark ~$\vert$ \pagemark}
\renewcommand*{\chaptermarkformat}{\chaptername{} \thechapter:\enskip}
\renewcommand*{\headfont}{}

\DeclareMathVersion{mathchartertext}
\SetSymbolFont{letters}{mathchartertext}{OML}{mdbch}{m}{n}

\titleformat{\section}[hang]
            {\usefont{T1}{bch}{b}{n}\selectfont} % format: \usefont{encoding}{family}{series}{shape}
            {}                                   % label
            {0em}                                % sep between label and title
            {\hspace{-0.4pt}
              \Large \thesection\hspace{0.6em}
            }                                    % before code
            []                                   % after code

\titleformat{\chapter}[display]                       % shape
            {\usefont{T1}{qhv}{b}{n}\selectfont\huge} % format: sans-serif
            {\chaptertitlename\ \thechapter}          % label
            {20pt}                                    % sep
            {\Huge}[\vspace{2ex}\titlerule]           % before code

\begin{document}
\title{Title}
\author{Name}
\maketitle

\clearpage
\tableofcontents{\thispagestyle{empty}}
\clearpage

\mainmatter
\chapter*{Introduction}
\addcontentsline{toc}{chapter}{Introduction}
\markboth{Introduction}{Introduction}
\thispagestyle{empty}
\lipsum[1-20]

\chapter{Another Chapter}
\thispagestyle{empty}
\section{A section}
\lipsum[1-20]

\end{document}

Note that scrpage2 is deprecated. So I would suggested to use ist successor scrlayer-scrpage

\usepackage[headsepline,markcase=noupper,forceoverwrite]{scrlayer-scrpage}
\automark[chapter]{chapter}
\clearpairofpagestyles
\ohead*{\leftmark ~$\vert$ \pagemark}
\renewcommand*{\chaptermarkformat}{\chaptername{} \thechapter:\enskip}
\setkomafont{pagehead}{\normalfont\normalsize\upshape}

The option forceoverwrite is needed because titlesec also defines the commands \newpagestyle and \renewpagestyle.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .