# How to change the page number for the scrartcl class to # of ## pages on the first page

I can achieve this for the regular article class and the fancyhdr package according to an answer to question: How can I add "page # of ##" on my document?

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyfoot[C]{\thepage\ of \pageref{LastPage}}
\fancypagestyle{plain}{%
\fancyhf{}%
\fancyfoot[C]{\thepage\ of \pageref{LastPage}}}


unfortunately this fancyhdr clashes with the scrartcl class and I get a recommendation to use another KOMA-Script package instead of fancyhdr. Do you know what the analogue of the code above looks like for KOMA-Script?

With a KOMA-Script class this can be done without a package for header and footer. You only have to redefine the KOMA-Script command \pagemark:

\documentclass[12pt]{scrartcl}
\usepackage{blindtext}
\usepackage{lastpage}
\renewcommand\pagemark{{\usekomafont{pagenumber}\thepage\ of \pageref{LastPage}}}

\author{Author}
\title{Title}
\begin{document}
\maketitle
\section{Testing}
\blinddocument
\end{document}


It is also possible to add lines below the header and above the footer. If you set pagestyle headings you will get the sections in header.

\documentclass[12pt,
]{scrartcl}
\usepackage{blindtext}
\usepackage{lastpage}
\renewcommand\pagemark{{\usekomafont{pagenumber}\thepage\ of \pageref{LastPage}}}

\author{Author}
\title{Title}
\begin{document}
\maketitle
\section{Testing}
\blinddocument
\end{document}


If you want to customize header and footer, you can use package scrlayer-scrpage which is part of the KOMA-Script bundle:

\documentclass[12pt]{scrartcl}
\usepackage{blindtext}
\usepackage{lastpage}
\renewcommand\pagemark{{\usekomafont{pagenumber}\thepage\ of \pageref{LastPage}}}
\clearpairofpagestyles
\ofoot*{\pagemark}

\author{Author}
\title{Title}
\begin{document}
\maketitle
\section{Testing}
\blinddocument
\end{document}


The starred version of \ofoot sets the entry for both scrheadings and plain.

• thank you very much indeed, why does one need the \pagestyle{headings}? – Dieter.Wilhelm Feb 27 '18 at 9:50
• You need \pagestyle{headings} if the section title should be in header (see page 2 of the second example). – esdd Feb 27 '18 at 9:54

Please see the following MWE. Important code is marked with <=======.

\documentclass[a4paper, oneside, 12pt]{scrartcl}

\usepackage[%
% automark places section title in header. Also enables placement in footer.
automark
]{scrlayer-scrpage} % <=================================================

\usepackage[a4paper,
vmargin=2cm, hmargin=2cm, % page margins
footskip=2em]
{geometry}

\usepackage{blindtext}
\usepackage{lastpage} % <===============================================

\ifoot{}
\cfoot{\thepage\ of \pageref{LastPage}} % <=============================
\ofoot{}

It uses scrlayer-scrpage and lastpage with the following result:
• @Au101 Ups, I oversaw that. I changed the code and use now \thepage instead of \pagemark, which uses explicitly \usekomafont{pagenumber}, resulting in an different font for the current page number ... – Mensch Feb 27 '18 at 14:43