The class scrletter
is an undocumented wrapper-class. It loads class scrartcl
with font size 12pt
and package scrletter
.
\pagemark
is already defined by the KOMA-Script scrartcl
. Therefore package scrletter
defines \letterpagemark
for the letters in the document. If the format of the page numbers in the letters should be the same as in the other part of the document, use
\let\letterpagemark\pagemark
before environment letter
.
\documentclass[
%12pt,% default
headheight=30pt,headinclude,
firsthead=false,firstfoot=false,
foldmarks=false,
%foldmarks=blmtP,% disabled by foldmarks=false
%fromalign=center,% disabled by firsthead=false
%fromphone,fromemail,% disabled by firsthead=false
%version=last,
backaddress=false,
subject=titled,
twoside=semi,
cleardoublepage=current
]{scrletter}
%\usepackage{scrlayer-scrpage}% load by package scrletter
\usepackage{lipsum}% only for dummy text
\usepackage[T1]{fontenc}
\clearpairofpagestyles
\ohead{\jobname.tex\hspace{0.5cm}\usekomavar{date}}
\cfoot{\pagemark}
\renewcommand*{\pagemark}{{\usekomafont{pagenumber}{\thepage\ of \pageref{LastPage}}}}
\let\letterpagemark\pagemark
\AddToHook{shipout/lastpage}{\label{LastPage}}% replaces package lastpage
\renewcommand*{\letterpagestyle}{scrheadings}% page style for the next pages of the letter
\AddToHook{cmd/opening/after}{\thispagestyle{\letterpagestyle}}% use the same page style on first letter page
\setkomavar{date}{19th February, 2022}% do not change \today
\begin{document}
\begin{letter}{Name}
\opening{Dear Name,}
\thispagestyle{scrheadings}
\lipsum
\end{letter}
\lipsum
\end{document}
Note:
\renewcommand*{\letterpagestyle}{scrheadings}% page style for the next pages of the letter
\AddToHook{cmd/opening/after}{\thispagestyle{\letterpagestyle}}% use the same page style on first letter page
can be replaced by
\renewcommand*\letterpagestyle{}% do not change the page style for the letter
\AddToHook{cmd/opening/after}{\thispagestyle{scrheadings}}% use scrheadings on first letter page
The result would be the same.
I believe there are two misunderstandings causing you to be confused.
Why is does the page style change when there are several pages?
It is a common typographical convention not to use headers on pages where a chapter starts. This let's the chapter heading be the first thing on the page without capping it with a header (that would usually just contain the chapter heading again).
In order to accommodate for this, LaTeX has the command \thispagestyle
which changes the page style for this page only, i.e. it will reset to the default before the next page (as opposed to \pagestyle
which changes the page style globally). By default, when you use \chapter
, somewhere in the code there is a \thispagestyle{plain}
that sets the page style for the page where the chapter starts to plain
.
By default, the plain
style has the page number in the footer and nothing in the header (this is also the default page style for the whole document). You changed that using fancyhdr
which is why you see your custom style on the chapter heading page.
So why does my page style not work on the rest of the document? I changed the default, didn't I?
and here's the second misunderstanding. What \pagestyle{plain}
does is not actually telling LaTeX "use the page style plain
from now on". Instead, it says "from now on, put the page number in the footer and nothing in the header". That is, it sets the style according to plain
, the fact that these settings came from plain
is immediately forgotten.
Because of this, just changing the definition of a page style will never take effect in your document, even if you have activated it previously using \pagestyle
. It only takes effect when you activate it again. In your example, this is done for the first page by \chapter
(using \thispagestyle{plain}
) but not for any other pages. That is why the default definitions are still in effect for those pages.
What all this means is that all you have to do to get what you expect is say
\pagestyle{plain}
after your \fancypagestyle
definition. This will activate the settings you just defined and make them the document default.
Best Answer
Without additional packages (except
lastpage
to capture the last page number):The popular package
fancyhdr
offers more versatility to control the headers and footers.