I decided to learn Scrlayer-Scrpage since I'm using a KOMA-script, but I couldn't replicate the result I had achieved using Fancyhdr.
Here's the one with Fancyhdr:
\documentclass[oneside, openany]{scrbook}
\usepackage{lipsum}
\usepackage{fancyhdr}
\fancypagestyle{my_style}{
\fancyhf{}
\fancyhead[RO]{\leftmark}
\fancyhead[LE]{\rightmark}
\fancyhead[LO,RE]{\thepage}
}
\pagestyle{my_style}
\fancypagestyle{plain}{
\fancyhf{}
\fancyfoot[C]{\thepage}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0.4pt}
}
\usepackage{etoc}
\renewcommand{\etocaftertitlehook}{\pagestyle{plain}}
\renewcommand{\etocaftertochook}{\thispagestyle{plain}}
\begin{document}
\title{title}
\maketitle
\tableofcontents
\thispagestyle{empty}
\addtocontents{toc}{\protect\thispagestyle{empty}}
\addchap{Copyright}
\pagenumbering{roman}
\chapter{Chapter}
\pagenumbering{arabic}
\section{hello}
\lipsum[1-20]
\end{document}
It has achieved the followings:
- Using etoc, ToC is not numbered or lined even if it exceeds 1 page.
- Except the first pages of a chapter, a line is drawn above the contents.
This is my attempt using Scrlayer-Scrpage:
\documentclass[oneside, openany, headsepline]{scrbook}
\usepackage{lipsum}
\usepackage[]{scrlayer-scrpage}
\clearpairofpagestyles
\ihead{\pagemark}
\ohead{\headmark}
\usepackage{etoc}
\renewcommand{\etocaftertitlehook}{\pagestyle{plain}}
\renewcommand{\etocaftertochook}{\thispagestyle{plain}}
\begin{document}
\title{title}
\maketitle
\tableofcontents
\thispagestyle{empty}
\addtocontents{toc}{\protect\thispagestyle{empty}}
\addchap{Copyright}
\pagenumbering{roman}
\chapter{Chapter}
\pagenumbering{arabic}
\section{hello}
\lipsum[1-20]
\end{document}
It does have succeeded in not numbering the ToC, but I couldn't find a way to distinguish the first pages of a chapter. The manual of Scrlayer-Scrpage sometimes lists several options without even telling where to put them, and I couldn't find any solution.
Beside the question above, I also want to know how to change the headmarks in both packages. Fancyhdr prints it as Chapter 1. and Scrlayer-Scrpage just as 1.
Best Answer
The page style of first page of a chapter of most book classes, distinguishes from the page style of the other pages. Standard class
book
uses hard coded\thispagestyle{plain}
for the first page of a\chapter
. KOMA-Script classscrbook
uses\thispagestyle{\chapterpagestyle}
and the default of\chapterpagestyle
isplain
too.And if you have a look at the result of your
scrlayer-scrpage
example:there are several differences between the first page of the chapter (left side) and other pages (right side):
This first is, because option
headsepline
does not set a head separation rule on page style plain. You could switch it on usingplainheadsepline
. But I think, you do not want it. So this is goodThe second is, because you have removed the defaults for page style
scrheadings
andplain.scrheadings
(which is the same likeplain
after the\pagestyle{scrheadings}
, that is done while loadingscrlayer-scrpage
) using\clearpairofpagestyls
and you've added\headmark
only toscrheadings
but not toplain.scrheadings
. That is absolutely correct.The third has almost the same reason as the second, but you've added
\pagemark
only toscrheadings
. So if you like to have a page number on the first page of a chapter, you have to add\pagemark
toplain.scrheadings
. This could be done replacing\ihead
by\ihead*
. But this would add the page number to the head. I think, you want the page number at the middle of the foot. So you have to useNote, the optional argument of
\cfoot
etc. does change the corresponding element of the plain page style.So with:
You will get
You could even remove using
etoc
and use\BeforeStartingTOC
and\AfterStartingTOC
to set the first page of the table of contents using page styleempty
but the rest of the table of contents with page styleplain
:BTW: Your
fancyhdr
definition distinguish from your description. It does also set a separation line on theplain
pages. I would not recommend this, but you can do it:Here I've used
\AddToLayerPageStyleOptions
to set KOMA-Script optionfootsepline
depending on the selected page styleIf you also want to have upper case running head see option
markcase
in the KOMA-Script manual. If you want the prefixCHAPTER
see\chaptermarkformat
. If you want to change the font, see elementspageheadfoot
,pagehead
,pagenumber
and commands\setkomafont
and\addtokomafont
.