ヘッダーのページ番号を余白に配置するにはどうすればよいでしょうか?

ヘッダーのページ番号を余白に配置するにはどうすればよいでしょうか?

次のコードを使用していますが、左ページではヘッダーを左揃えにし、右ページではヘッダーを右揃えにし、ページ番号を定義されたジオメトリ内ではなく余白に配置する方法がわかりません。

\makeatletter
\def\chapapp2{Chapter}

\def\appendix{\par
 \setcounter{chapter}{0}
 \setcounter{section}{0}
 \def\chapapp2{Appendix}
 \def\@chapapp{Appendix}
 \def\thechapter{\Alph{chapter}}}

\def\ps@uheadings{\let\@mkboth\markboth
% modifications
\def\@oddhead{\protect\makebox[\textwidth][l]
        {\small\scshape\MakeUppercase{\rightmark}\hfill\thepage}}
\def\@oddfoot{}
\def\@evenfoot{}
\def\@evenhead{\protect\makebox[\textwidth][l]
        {\thepage\hfill\small\scshape\MakeUppercase{\leftmark}}}
% end of modifications
\def\chaptermark##1{\markboth {\ifnum \c@secnumdepth >\m@ne
 \chapapp2\ \thechapter. \ \fi ##1}{}}%
\def\sectionmark##1{\markright {\ifnum \c@secnumdepth >\z@
   \thesection. \ \fi ##1}}}
\makeatother

関連情報