You could also use KOMA-Script package scrlayer-scrpage
. It is the successor of the deprecated package scrpage2
.
scrlayer-scrpage
uses layer to declare pagestyles. So you can declare a new layer for the pagenumber in the outer margin and add this layer to pagestyle scrheadings
and plain.scrheadings
. Note that after loading scrlayer-scrpage
pagestyle scrheadings
is set and pagestyle plain
is redefined as an aliaspagestyle for plain.scrheadings
.
\documentclass{scrbook}
\usepackage[automark]{scrlayer-scrpage}
\clearpairofpagestyles
\ohead{\headmark}
\DeclareNewLayer[
background,
outermargin,
height=\textheight,
voffset=1in+\voffset+\topmargin+\headheight+\headsep,
contents={%
\vfill
\ifodd\value{page}\hspace*{.4\layerwidth}\else\hfill\fi
\pagemark
\ifodd\value{page}\else\hspace*{.4\layerwidth}\fi
\vfill
}
]{outermargin.pagenumber}
\AddLayersToPageStyle{scrheadings}{outermargin.pagenumber}
\AddLayersToPageStyle{plain.scrheadings}{outermargin.pagenumber}
\addtokomafont{pagenumber}{\Huge}
\usepackage{blindtext}% <- only for dummy text
\begin{document}
\chapter{Fruits}
\section{Bananas}
\Blindtext[20]
\end{document}
results in