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

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

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

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

\usepackage[a4paper,
  vmargin=2cm, hmargin=2cm, % page margins
  includehead, includefoot, % Margins calculated include header and footer
  footskip=2em]
{geometry}

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

\ihead{\rightmark}
\chead{}
\ohead{\leftmark}
\ifoot{}
\cfoot{\thepage\ of \pageref{LastPage}} % <=============================
\ofoot{}
\pagestyle{scrheadings}

\begin{document}
\section{Testing}
\blinddocument
\end{document}

It uses scrlayer-scrpage and lastpage with the following result:

enter image description here


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}

enter image description here

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,
  headsepline,footsepline% <- added
]{scrartcl}
\usepackage{blindtext}
\usepackage{lastpage}
\renewcommand\pagemark{{\usekomafont{pagenumber}\thepage\ of \pageref{LastPage}}}
\pagestyle{headings}% <- added

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

enter image description here


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}}}
\usepackage{scrlayer-scrpage}% sets pagestyle scrheadings automatically
\clearpairofpagestyles
\ohead{\headmark}
\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.

enter image description here