%%% 水平移動量の計算
\setbox\z@\hbox{\hskip5mm\@bannerfont\the\@bannertoken}
\dimen@\wd\z@ \advance\dimen@5mm
\edef\@put@totalpage@hshift{\the\dimen@}
\def\@put@totalpage{%
   \rlap{%
      \vbox to\z@{\vss
         \hbox to\z@{%
            \dimen@\@saved@oddsidemargin
            \if@twoside \ifodd\c@page\else
               \dimen@\@saved@evensidemargin
            \fi\fi
            \hskip-\dimen@
            \hbox to\paperwidth{%%% (*)表示を変えるならこの付近を変更
               \hskip\@put@totalpage@hshift
               \normalfont\ttfamily\#\number\@totalpage
               \hfil}%
            \hss}%
         %%% 垂直移動量の計算
         \dimen@\headheight
         \advance\dimen@\topmargin \advance\dimen@ 1in
         \advance\dimen@ 8mm \advance\dimen@4\p@
         \vskip\dimen@}}}
%%% 総ページ数を取得するための細工
\newcount\@totalpage
\let\@primitive@shipout\shipout
\def\shipout{%
   \global\advance\@totalpage\@ne
   \@primitive@shipout}
%%% 左右の余白量の保存
\dimen@\oddsidemargin \advance\dimen@ 1in
\edef\@saved@oddsidemargin{\the\dimen@}
\dimen@\evensidemargin \advance\dimen@ 1in
\edef\@saved@evensidemargin{\the\dimen@}
%%% 各ページスタイルの再定義
\def\ps@plain{%
  \let\@mkboth\@gobbletwo
  \let\@oddfoot\@empty
  \let\@evenfoot\@empty
  \def\@evenhead{\@put@totalpage\hss
    \hbox to \fullwidth{\textbf{\thepage}\hfil}}%
  \def\@oddhead{\@put@totalpage%
    \hbox to \fullwidth{\hfil\textbf{\thepage}}\hss}}


% \def\ps@plainhead{%
%   \let\@mkboth\@gobbletwo
%   \let\@oddfoot\@empty
%   \let\@evenfoot\@empty
%   \def\@evenhead{\@put@totalpage\hss
%     \hbox to \fullwidth{\textbf{\thepage}\hfil}}%
%   \def\@oddhead{\@put@totalpage%
%     \hbox to \fullwidth{\hfil\textbf{\thepage}}\hss}}

\def\ps@plainhead{%
  \let\@mkboth\@gobbletwo
  \let\@oddfoot\@empty
  \let\@evenfoot\@empty
  \def\@evenhead{\@put@totalpage%
    \if@mparswitch \hss \fi
    \hbox to \fullwidth{\textbf{\thepage}\hfil}%
    \if@mparswitch\else \hss \fi}%
  \def\@oddhead{\@put@totalpage%
    \hbox to \fullwidth{\hfil\textbf{\thepage}}\hss}}
%\if@report \let\ps@plain\ps@plainfoot \else \let\ps@plain\ps@plainhead \fi

% \def\ps@headings{%
%   \let\@oddfoot\@empty
%   \let\@evenfoot\@empty
%   \def\@evenhead{\@put@totalpage\hss
%     \underline{\hbox to \fullwidth{\autoxspacing
%         \textbf{\thepage}\hfil\leftmark}}}%
%   \def\@oddhead{\@put@totalpage\underline{\hbox to \fullwidth{\autoxspacing
%         {\rightmark}\hfil\textbf{\thepage}}}\hss}%
%   \let\@mkboth\markboth
%   \def\chaptermark##1{\markboth{%
%     \ifnum \c@secnumdepth >\m@ne
%       \if@mainmatter
%         \@chapapp\thechapter\@chappos\hskip1zw
%       \fi
%     \fi
%     ##1}{}}%
%   \def\sectionmark##1{\markright{%
%     \ifnum \c@secnumdepth >\z@ \thesection \hskip1zw\fi
%     ##1}}}%

\def\ps@headings{%
  \let\@oddfoot\@empty
  \let\@evenfoot\@empty
  \def\@evenhead{\@put@totalpage%
    \if@mparswitch \hss \fi
    \underline{\hbox to \fullwidth{\autoxspacing
        \textbf{\thepage}\hfil\leftmark}}%
    \if@mparswitch\else \hss \fi}%
  \def\@oddhead{\@put@totalpage\underline{\hbox to \fullwidth{\autoxspacing
        {\if@twoside\rightmark\else\leftmark\fi}\hfil\textbf{\thepage}}}\hss}%
  \let\@mkboth\markboth
  \def\chaptermark##1{\markboth{%
    \ifnum \c@secnumdepth >\m@ne
      \if@mainmatter
        \@chapapp\thechapter\@chappos\hskip1zw
      \fi
    \fi
    ##1}{}}%
  \def\sectionmark##1{\markright{%
    \ifnum \c@secnumdepth >\z@ \thesection \hskip1zw\fi
    ##1}}}%

% \def\ps@myheadings{%
%   \let\@oddfoot\@empty\let\@evenfoot\@empty
%   \def\@evenhead{\@put@totalpage\thepage\hfil\leftmark}%
%   \def\@oddhead{{\@put@totalpage\rightmark}\hfil\thepage}%
%   \let\@mkboth\@gobbletwo
%   \let\chaptermark\@gobble
%   \let\sectionmark\@gobble
% }

\def\ps@myheadings{%
  \let\@oddfoot\@empty\let\@evenfoot\@empty
  \def\@evenhead{\@put@totalpage%
    \if@mparswitch \hss \fi%
    \hbox to \fullwidth{\thepage\hfil\leftmark}%
    \if@mparswitch\else \hss \fi}%
  \def\@oddhead{\@put@totalpage%
    \hbox to \fullwidth{\rightmark\hfil\thepage}\hss}%
  \let\@mkboth\@gobbletwo
  \let\chaptermark\@gobble
  \let\sectionmark\@gobble
}


\def\ps@empty{%
  \let\@mkboth\@gobbletwo
  \def\@oddhead{\@put@totalpage\hfil}%
  \let\@oddfoot\@empty
  \def\@evenhead{\@put@totalpage\hfil}%
  \let\@evenfoot\@empty}

% \def\ps@@fancy{%
%   \ps@@empty % This is for amsbook/amsart, which do strange things with \topskip
%   \def\@mkboth{\protect\markboth}%
%   \def\@oddhead{\@put@totalpage\@fancyhead\@lodd\f@ncyolh\f@ncyoch\f@ncyorh\@rodd}%
%   \def\@oddfoot{\@fancyfoot\@lodd\f@ncyolf\f@ncyocf\f@ncyorf\@rodd}%
%   \def\@evenhead{\@put@totalpage\@fancyhead\@rodd\f@ncyelh\f@ncyech\f@ncyerh\@lodd}%
%   \def\@evenfoot{\@fancyfoot\@rodd\f@ncyelf\f@ncyecf\f@ncyerf\@lodd}%
% }

\def\ps@@fancy{%
  \ps@@empty % This is for amsbook/amsart, which do strange things with \topskip
  \def\@mkboth{\protect\markboth}%
  \def\@oddhead{\@put@totalpage\@fancyhead\fancy@Oolh\f@ncyolh\f@ncyoch\f@ncyorh\fancy@Oorh}%
  \def\@oddfoot{\@fancyfoot\fancy@Oolf\f@ncyolf\f@ncyocf\f@ncyorf\fancy@Oorf}%
  \def\@evenhead{\@put@totalpage\@fancyhead\fancy@Oelh\f@ncyelh\f@ncyech\f@ncyerh\fancy@Oerh}%
  \def\@evenfoot{\@fancyfoot\fancy@Oelf\f@ncyelf\f@ncyecf\f@ncyerf\fancy@Oerf}%
}


%\pagestyle{headings}
%\makeatother
