# svmono.cls: how to add line below header?

How can I add a line under the headers of normal pages (i.e. not chapter pages, or TOC, etc) using the svmono class? Below is an example of what I'm trying to achieve: I'd like the headers in pages 2 & 3 to have a line below them, spanning all the page width, as shown in the 2nd figure. A copy of svmono.cls can be found here. The code that defines the headers seems to be the following, how can I insert a page-wide rule in this code?:

Snippet of svmono.cls (lines 1917-1927):

\def\ps@headings{\let\@mkboth\markboth
\let\@oddfoot\@empty\let\@evenfoot\@empty
\def\@evenhead{\runheadsize\runheadstyle\rlap{\thepage}\hfil
\leftmark}
\def\@oddhead{\runheadsize\runheadstyle\rightmark\hfil
\llap{\thepage}}
\def\chaptermark##1{\markboth{{\if@chapnum
\thechapter\thechapterend\hskip\betweenumberspace\fi ##1}}{{\if@chapnum
\thechapter\thechapterend\hskip\betweenumberspace\fi ##1}}}
\def\sectionmark##1{\markright{{\ifnum\c@secnumdepth>\z@
\thesection\seccounterend\hskip\betweenumberspace\fi ##1}}}}


Notes:

1) Modifications to svmono.cls are OK (this is not intended to be send to the publisher)

2) I tried using fancyhdr, but it totally messes the style of the header.

Example:

\documentclass[envcountchap,envcountchap]{svmono}
\usepackage[paperheight=220mm,paperwidth=140mm,top=1.5cm,bottom=1.5cm,inner=1cm,outer=1cm]{geometry}
\usepackage{mathptmx}
\usepackage{lipsum}
\begin{document}
\chapter{Title of chapter}
\section{Title of section}
\lipsum[1-14]
\end{document}


Actual output (undesired):

Desired output:

Updated example (titleps almost solves it, but breaks in the bibliography!):

\documentclass[envcountchap,envcountchap]{svmono}
\usepackage[paperheight=220mm,paperwidth=140mm,top=1.5cm,bottom=1.5cm,inner=1cm,outer=1cm]{geometry}
\usepackage{mathptmx}
\usepackage{lipsum}

\usepackage{titleps}
\newpagestyle{withheadrule}{%
\headrule
\sethead[\footnotesize\thepage][][\footnotesize\thechapter~\chaptertitle]{\footnotesize\thesection~\sectiontitle}{}{\footnotesize\thepage}
\setfoot{}{}{}
}
\pagestyle{withheadrule}

\begin{document}
\chapter{Title of chapter}
\section{Title of section}
\lipsum[1-14]
\cite{dummy1,dummy2,dummy3,dummy4}

\backmatter
\bibliographystyle{plain}
\bibliography{./sample}

\end{document}


Contents of sample.bib:

@misc{dummy1,author="Dummy 1",title={\lipsum[1-4]}}
@misc{dummy2,author="Dummy 2",title={\lipsum[1-4]}}
@misc{dummy3,author="Dummy 3",title={\lipsum[1-4]}}
@misc{dummy4,author="Dummy 4",title={\lipsum[1-4]}}


Updated example output (last pages; note spurious "Reference" text added in header and footer):

Solution with fancyhdr: how to define it only on a part of the document?

\documentclass[envcountchap,envcountchap]{svmono}
\usepackage[paperheight=220mm,paperwidth=140mm,top=1.5cm,bottom=1.5cm,inner=1cm,outer=1cm,heightrounded]{geometry}
\usepackage{newtxtext,newtxmath} % <--- not mathptmx
\usepackage{fancyhdr}

\pagestyle{fancy}
\fancyhf{}
\fancyhead[RE]{\runheadsize\runheadstyle\leftmark}
\fancyhead[LO]{\runheadsize\runheadstyle\rightmark}
\fancyhead[LE,RO]{\runheadsize\runheadstyle\thepage}
\fancypagestyle{plain}{%
\renewcommand{\headrulewidth}{0pt}%
\fancyhf{}%
\fancyfoot[RE,LO]{\runheadsize\runheadstyle\thepage}%
}
\makeatletter
\renewcommand\chaptermark[1]{%
\markboth{%
\if@chapnum\thechapter\thechapterend\hskip\betweenumberspace\fi #1%
}{%
\if@chapnum\thechapter\thechapterend\hskip\betweenumberspace\fi #1%
}%
}
\renewcommand{\sectionmark}[1]{%
\markright{%
\ifnum\c@secnumdepth>\z@ \thesection\seccounterend\hskip\betweenumberspace\fi #1%
}%
}
\makeatother

% How to define a "normal" page style? or invoke the default style (i.e. non-fancy)?
\fancypagestyle{test}{%
}

\usepackage{lipsum}

\begin{document}
\pagestyle{test}
\tableofcontents

\chapter{Title of chapter}
\section{Title of section}
\lipsum[1-14]
\cite{dummy1,dummy2,dummy3,dummy4}

\pagestyle{test}

\backmatter
\bibliographystyle{plain}
\bibliography{./sample}

\end{document}


## 2 Answers

You can use fancyhdr, but also applying the definitions of \chaptermark and \sectionmark.

\documentclass[envcountchap,envcountchap]{svmono}
\usepackage[
paperheight=220mm,
paperwidth=140mm,
top=1.5cm,
bottom=1.5cm,
inner=1cm,
outer=1cm,
heightrounded, % <--- don't forget
]{geometry}
\usepackage{newtxtext,newtxmath} % <--- not mathptmx
\usepackage{fancyhdr}

\pagestyle{fancy}
\fancyhf{}
\fancyhead[RE]{\runheadsize\runheadstyle\leftmark}
\fancyhead[LO]{\runheadsize\runheadstyle\rightmark}
\fancyhead[LE,RO]{\runheadsize\runheadstyle\thepage}
\fancypagestyle{plain}{%
\renewcommand{\headrulewidth}{0pt}%
\fancyhf{}%
\fancyfoot[RE,LO]{\runheadsize\runheadstyle\thepage}%
}
\makeatletter
\renewcommand\chaptermark[1]{%
\markboth{%
\if@chapnum\thechapter\thechapterend\hskip\betweenumberspace\fi #1%
}{%
\if@chapnum\thechapter\thechapterend\hskip\betweenumberspace\fi #1%
}%
}
\renewcommand{\sectionmark}[1]{%
\markright{%
\ifnum\c@secnumdepth>\z@ \thesection\seccounterend\hskip\betweenumberspace\fi #1%
}%
}
\makeatother

\usepackage{lipsum}

\begin{document}

\tableofcontents

\chapter{Title of chapter}
\section{Title of section}
\lipsum[1-14]

\chapter{A}\section{AA}\section{AB}\section{AC}
\chapter{A}\section{AA}\section{AB}\section{AC}
\chapter{A}\section{AA}\section{AB}\section{AC}
\chapter{A}\section{AA}\section{AB}\section{AC}
\chapter{A}\section{AA}\section{AB}\section{AC}
\chapter{A}\section{AA}\section{AB}\section{AC}
\chapter{A}\section{AA}\section{AB}\section{AC}
\chapter{A}\section{AA}\section{AB}\section{AC}
\chapter{A}\section{AA}\section{AB}\section{AC}
\chapter{A}\section{AA}\section{AB}\section{AC}
\chapter{A}\section{AA}\section{AB}\section{AC}
\chapter{A}\section{AA}\section{AB}\section{AC}
\chapter{A}\section{AA}\section{AB}\section{AC}
\chapter{A}\section{AA}\section{AB}\section{AC}

\chapter{A}\section{AA}\section{AB}\section{AC}
\chapter{A}\section{AA}\section{AB}\section{AC}
\chapter{A}\section{AA}\section{AB}\section{AC}
\chapter{A}\section{AA}\section{AB}\section{AC}
\chapter{A}\section{AA}\section{AB}\section{AC}
\chapter{A}\section{AA}\section{AB}\section{AC}
\chapter{A}\section{AA}\section{AB}\section{AC}
\chapter{A}\section{AA}\section{AB}\section{AC}
\chapter{A}\section{AA}\section{AB}\section{AC}
\chapter{A}\section{AA}\section{AB}\section{AC}
\chapter{A}\section{AA}\section{AB}\section{AC}
\chapter{A}\section{AA}\section{AB}\section{AC}

\end{document}


I added a wealth of fake chapters in order to populate the table of contents and see that the headers in it are correct.

Don't use mathptmx, which is a hack that did what was possible 20 years ago. If you want Times for text and math, the combination newtxtext and newtxmath is far better.

• Thanks so much for this solution egreg; it solves the problem! Is there a way I can apply these definitions only to a part of the document? For instance, is there a way to apply the "fancy" page style only to the chapters, and not to the ToC and References? (In my actual document I am getting the header line in some blank pages created by \cleardoublepage, so I'd like to avoid the header style in these pages, which are located at the beginning and at the end of the document) – dontpanic Jul 15 '18 at 18:10
• @dontpanic Define more styles with \fancypagestyle and apply them where needed. – egreg Jul 15 '18 at 18:13
• Hum, not really sure how to achieve that :( I added an example (see bottom of original post); I defined an empty style "test" and tried to apply it using \pagestyle to the bibliography, but the headers still have the line in this section... what am I missing? – dontpanic Jul 15 '18 at 18:48

It seems titleps, the companion package of titlesec can live peacefully with the svmono class:

\documentclass[envcountchap,envcountchap]{svmono}
\usepackage[paperheight=220mm,paperwidth=140mm,top=1.5cm,bottom=1.5cm,inner=1cm,outer=1cm]{geometry}
\usepackage{mathptmx}
\usepackage{lipsum}
\usepackage{titleps}
\newpagestyle{withheadrule}{%
\headrule
\sethead[\footnotesize\thepage][][\footnotesize\thechapter~\chaptertitle]{\footnotesize\thesection~\sectiontitle}{}{\footnotesize\thepage}
\setfoot{}{}{}
}
\pagestyle{withheadrule}

\begin{document}

\chapter{Title of chapter}
\section{Title of section}
\lipsum[1-14]

\end{document}


• Thank you Bernard, that totally does the trick! Is there a way to tweak the thickness of the rule drawn? – dontpanic Jul 14 '18 at 21:08
• @dontpanic: You should write in your preamble: \AtBeginDocument{\setheadrule{some thickness}}. If you want to add some colour, you have to redefine \makeheadrule. – Bernard Jul 14 '18 at 21:23
• Bernard: unfortunately, this solution breaks in the bibliography (see updated example) :( ...any ideas on how to get it to work also there? – dontpanic Jul 14 '18 at 22:50
• ...it seems the spurious text "References" is added both at the header and footer. Any idea on how to get rid of it? – dontpanic Jul 14 '18 at 23:02