1

I'm trying to create a letter template and want every page to show the current page and the total number of pages. However, I cannot get koma script to display the custom \pagemark on the first page. It always starts on the second. At the same time, the header is to be shown only at the second page as the first page has a custom header.

MRE

\documentclass{scrlttr2}
\KOMAoption{paper}{a4}
\KOMAoption{firsthead}{yes}
\KOMAoption{firstfoot}{yes}

\usepackage{blindtext}

\pagestyle{myheadings} \markright{\Ifkomavarempty{subject}{}{\centering\usekomavar{subject}}} \renewcommand\pagemark{{\usekomafont{pagenumber}custom~pg~\thepage}}

\begin{document}

\setkomavar{fromname}{sender} \setkomavar{fromaddress}{address} \setkomavar{firsthead}{Custom firsthead} % the following workaround doesn't work as intended % because the bottom spacing of the 'firstfoot' is % different from the regular footer distance %%\setkomavar{firstfoot}{% %%\centering\pagemark% %%} \setkomavar{date}{Date} \setkomavar{subject}{Subject}

\begin{letter}{Addressee} \opening{Hello} World \Blindtext \closing{Cheers}

\end{letter} \end{document}

The custom pagemark is shown on the second page but not the first:

rendered document

bitmask
  • 1,205

1 Answers1

1

You could add \thispagestyle{plain} after \opening{...} to change the page style of the first page from empty to plain:

\KOMAoption{firstfoot}{no}% <- changed: disable firstfoot
...
\opening{Hello}
\thispagestyle{plain}% <- added

Note that you have to disable firstfoot. See also https://tex.stackexchange.com/a/578081/43317.

Example:

\documentclass{scrlttr2}
%\KOMAoption{paper}{a4}% default
%\KOMAoption{firsthead}{yes}% default
\KOMAoption{firstfoot}{no}% <- changed: disable firstfoot
\usepackage{blindtext}

\pagestyle{myheadings} \setkomavar{nexthead}{\parbox{\textwidth}{\centering\usekomavar{subject}}} \renewcommand\pagemark{\usekomafont{pagenumber}{custom~pg~\thepage}}

\begin{document}

\setkomavar{fromname}{sender} \setkomavar{fromaddress}{address} \setkomavar{firsthead}{Custom firsthead} \setkomavar{date}{Date} \setkomavar{subject}{Subject}

\begin{letter}{Addressee} \opening{Hello} \thispagestyle{plain}% <- added

World \Blindtext \closing{Cheers} \end{letter} \end{document}

enter image description here

You could also patch \opening using

\KOMAoption{firstfoot}{no}% <- changed: disable firstfoot
...
\newcommand{\originalopening}{}
\let\originalopening\opening
\renewcommand{\opening}[1]{\originalopening{#1}\thispagestyle{plain}}

or

\KOMAoption{firstfoot}{no}% <- changed: disable firstfoot
...
\usepackage{xpatch}
\xpatchcmd{\opening}{\thispagestyle{empty}}{\thispagestyle{plain}}{}{\PatchFailed}

in the preamble.

Example:

\documentclass{scrlttr2}
%\KOMAoption{paper}{a4}% default
%\KOMAoption{firsthead}{yes}% default
\KOMAoption{firstfoot}{no}% <- changed: disable firstfoot
\usepackage{blindtext}

\pagestyle{myheadings} \setkomavar{nexthead}{\parbox{\textwidth}{\centering\usekomavar{subject}}} \renewcommand\pagemark{\usekomafont{pagenumber}{custom~pg~\thepage}}

\usepackage{xpatch} \xpatchcmd{\opening}{\thispagestyle{empty}}{\thispagestyle{plain}}{}{\PatchFailed}

\begin{document}

\setkomavar{fromname}{sender} \setkomavar{fromaddress}{address} \setkomavar{firsthead}{Custom firsthead} \setkomavar{date}{Date} \setkomavar{subject}{Subject}

\begin{letter}{Addressee} \opening{Hello} World \Blindtext \closing{Cheers} \end{letter} \end{document}

The result is the same as above.

esdd
  • 85,675