使用 KOMA 脚本重现彩色 fancyhdr 页脚

使用 KOMA 脚本重现彩色 fancyhdr 页脚

我正在尝试重现这个用 fancyhdr 制作的页脚,仅使用 KOMA 脚本,以避免混淆它们:

在此处输入图片描述

这是 fancyhdr MWE:

\documentclass{scrbook}
\usepackage{blindtext}
%\usepackage[automark]{scrlayer-scrpage}
%\pagestyle{scrheadings}
\usepackage{xcolor}

\usepackage[                    % page layout modifications
    paper=a4paper,                  %   - use A4 paper size
    %scale={0.86,0.94},             %   - total body size (h,v)
    %scale={0.86,0.94},             %   - total body size (h,v)
    nohead,                         %   - no header
    includefoot,                    %   - include footer space
    includemp,                      %   - include side note space
    bindingoffset=0.5cm,            %   - binding correction
    top=2.25cm,                     %   - total body: top margin
    left=3.75cm,                    %   - total body: left margin (odd pages)
    right=0.75cm,                   %   - total body: right margin (odd pages)
    bottom=1.5cm,                   %   - total body: bottom margin
    marginparwidth=1.75cm,          %   - width for side note
    marginparsep=10pt,              %   - space between notes and body text (content)
    footskip=2cm,                   %   - footer skip size
]{geometry}

% own font definitions
\newcommand{\helv}{\fontfamily{phv}\fontsize{9}{11}\selectfont}
\newcommand{\book}{\fontfamily{pbk}\fontseries{m}\fontsize{11}{13}\selectfont}
\newcommand{\tgherosfont}{\fontfamily{qhv}\selectfont}

\addtokomafont{disposition}{\usefont{T1}{bch}{b}{n}\selectfont} % set font for ToC, LoT


\definecolor{ctcolormain}{cmyk}{0, 1, .8, .2}%
\definecolor{ctcoloraccessory}{cmyk}{0, 0, 0, .7}%
\definecolor{ctcolorblack}{gray}{0}
\definecolor{ctcolorgray}{gray}{.5}
\definecolor{ctcolorgraylight}{gray}{.8}

\colorlet{ctcolorfooterpage}{ctcolorblack}
\colorlet{ctcolorfooterline}{ctcolormain}
\colorlet{ctcolorfootermark}{ctcolorblack}
\colorlet{ctcolorfootertitle}{ctcolormain}



\usepackage{fancyhdr}

\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{%
    \markboth{%
        \footnotesize%
        {\color{ctcolorfootermark}\textbf{\chaptername\ \thechapter}}%
        \quad%
        \if%
            {\color{ctcolorfootertitle}\parbox[t]{.7\textwidth}{#1}}%
        \else%
            {\color{ctcolorfootertitle}#1}%
        \fi%
    }{}%
}
\renewcommand{\sectionmark}[1]{%
    \markright{%
        \footnotesize%
        {\color{ctcolorfootermark}\textbf{\thesection}}%
        \quad%
        {\color{ctcolorfootertitle}#1}%
    }%
}
%
\fancypagestyle{plain}{%
    \fancyhf{}
    \fancyfootoffset[OR]{1.85cm}
    \fancyfoot[OR]{%
        {\ }\tgherosfont%
        {\color{ctcolorfooterline}\rule[-90pt]{1.25pt}{100pt}}%
        \hspace*{10pt}\begin{minipage}[b]{1.5cm}%
            \color{ctcolorfooterpage}\normalsize\textbf{\thepage}%
        \end{minipage}%
    }
    \fancyfootoffset[EL]{1.85cm}
    \fancyfoot[EL]{%
        \tgherosfont%
        \begin{minipage}[b]{1.5cm}%
            \raggedleft\color{ctcolorfooterpage}\normalsize\textbf{\thepage}%
        \end{minipage}%
        \hspace*{10pt}{\color{ctcolorfooterline}\rule[-90pt]{1.25pt}{100pt}}%
    }
    \renewcommand{\headrulewidth}{0pt}
    \renewcommand{\footrulewidth}{0pt}
}
%
\fancypagestyle{maincontentstyle}{%
    \pagestyle{plain}
    \fancyhf{}
    \fancyfootoffset[OR]{1.85cm}
    \fancyfoot[OR]{%
        {\ }\tgherosfont\footnotesize%
        \rightmark%
        \hspace*{0.75cm}{\color{ctcolorfooterline}\rule[-90pt]{1.25pt}{100pt}}%
        \hspace*{10pt}\begin{minipage}[b]{1.5cm}%
            \color{ctcolorfooterpage}\normalsize\textbf{\thepage}%
        \end{minipage}%
    }
    \fancyfootoffset[EL]{1.85cm}
    \fancyfoot[EL]{%
        \tgherosfont\footnotesize%
        \begin{minipage}[b]{1.5cm}%
            \raggedleft\color{ctcolorfooterpage}\normalsize\textbf{\thepage}%
        \end{minipage}%
        \footnotesize%
        \hspace*{10pt}{\color{ctcolorfooterline}\rule[-90pt]{1.25pt}{100pt}}%
        \hspace*{0.75cm}\leftmark%
    }
}

\begin{document}
\pagestyle{maincontentstyle}
\blinddocument
\pagestyle{plain}
\blinddocument
\end{document}

我正在读KOMA手册scrlayer-scrpage 的一部分,但是它相当复杂,我无法让它工作。

答案1

以下是使用的建议scrlayer-scrpage

\documentclass{scrbook}
\usepackage{blindtext}
\usepackage{xcolor}

\usepackage[                    % page layout modifications
    paper=a4paper,                  %   - use A4 paper size
    %scale={0.86,0.94},             %   - total body size (h,v)
    %scale={0.86,0.94},             %   - total body size (h,v)
    nohead,                         %   - no header
    includefoot,                    %   - include footer space
    includemp,                      %   - include side note space
    bindingoffset=0.5cm,            %   - binding correction
    top=2.25cm,                     %   - total body: top margin
    left=3.75cm,                    %   - total body: left margin (odd pages)
    right=0.75cm,                   %   - total body: right margin (odd pages)
    bottom=1.5cm,                   %   - total body: bottom margin
    marginparwidth=1.75cm,          %   - width for side note
    marginparsep=10pt,              %   - space between notes and body text (content)
    footskip=2cm,                   %   - footer skip size
]{geometry}

% own font definitions
\newcommand{\helv}{\fontfamily{phv}\fontsize{9}{11}\selectfont}
\newcommand{\book}{\fontfamily{pbk}\fontseries{m}\fontsize{11}{13}\selectfont}
\newcommand{\tgherosfont}{\fontfamily{qhv}\selectfont}

\addtokomafont{disposition}{\usefont{T1}{bch}{b}{n}\selectfont} % set font for ToC, LoT

\definecolor{ctcolormain}{cmyk}{0, 1, .8, .2}%
\definecolor{ctcoloraccessory}{cmyk}{0, 0, 0, .7}%
\definecolor{ctcolorblack}{gray}{0}
\definecolor{ctcolorgray}{gray}{.5}
\definecolor{ctcolorgraylight}{gray}{.8}

\colorlet{ctcolorfooterpage}{ctcolorblack}
\colorlet{ctcolorfooterline}{ctcolormain}
\colorlet{ctcolorfootermark}{ctcolorblack}
\colorlet{ctcolorfootertitle}{ctcolormain}

\usepackage[automark]{scrlayer-scrpage}% sets pagestyle scrheadings automatically
\clearpairofpagestyles
\lefoot{\hspace*{.75cm}\headmark}
\rofoot{\headmark\hspace*{.75cm}}

\newcommand*\pagenumberrule{%
  {\color{ctcolorfooterline}\rule[-90pt]{1.25pt}{100pt}}%
}
\DeclareNewLayer[
  foreground,
  oddpage,
  foot,
  contents={%
    \hfill
    \makebox[0pt][l]{%
      \pagenumberrule
      \hspace*{10pt}%
      \pagemark
    }%
  }
]{pagenumber.odd}
\DeclareNewLayer[
  foreground,
  evenpage,
  foot,
  contents={%
    \makebox[0pt][r]{%
      \pagemark
      \hspace*{10pt}%
      \pagenumberrule
    }%
  }
]{pagenumber.even}
\AddLayersToPageStyle{scrheadings}{pagenumber.odd,pagenumber.even}
\AddLayersToPageStyle{plain.scrheadings}{pagenumber.odd,pagenumber.even}

\setkomafont{pageheadfoot}{\color{ctcolorfootertitle}\tgherosfont\footnotesize}
\newkomafont{marknumber}{\color{ctcolorfootermark}\bfseries}
\setkomafont{pagenumber}{\color{ctcolorfooterpage}\tgherosfont\normalsize\bfseries}
\renewcommand\chaptermarkformat{{\usekomafont{marknumber}\chaptername\ \thechapter}\quad}
\renewcommand\sectionmarkformat{{\usekomafont{marknumber}\thesection}\quad}

\begin{document}
\blinddocument
\clearpage
\pagestyle{plain}
\blinddocument
\end{document}

在此处输入图片描述

但会出现关于头部高度太小的警告。您可以忽略这些警告,也可以nohead从包的选项中删除geometry

或者您可以使用包scrlayer并定义自己的不带标题层的图层页面样式:

\documentclass{scrbook}
\usepackage{blindtext}
\usepackage{xcolor}

\usepackage[                    % page layout modifications
    paper=a4paper,                  %   - use A4 paper size
    %scale={0.86,0.94},             %   - total body size (h,v)
    %scale={0.86,0.94},             %   - total body size (h,v)
    nohead,                         %   - no header
    includefoot,                    %   - include footer space
    includemp,                      %   - include side note space
    bindingoffset=0.5cm,            %   - binding correction
    top=2.25cm,                     %   - total body: top margin
    left=3.75cm,                    %   - total body: left margin (odd pages)
    right=0.75cm,                   %   - total body: right margin (odd pages)
    bottom=1.5cm,                   %   - total body: bottom margin
    marginparwidth=1.75cm,          %   - width for side note
    marginparsep=10pt,              %   - space between notes and body text (content)
    footskip=2cm,                   %   - footer skip size
]{geometry}

 %own font definitions
\newcommand{\helv}{\fontfamily{phv}\fontsize{9}{11}\selectfont}
\newcommand{\book}{\fontfamily{pbk}\fontseries{m}\fontsize{11}{13}\selectfont}
\newcommand{\tgherosfont}{\fontfamily{qhv}\selectfont}

\addtokomafont{disposition}{\usefont{T1}{bch}{b}{n}\selectfont} % set font for ToC, LoT

\definecolor{ctcolormain}{cmyk}{0, 1, .8, .2}%
\definecolor{ctcoloraccessory}{cmyk}{0, 0, 0, .7}%
\definecolor{ctcolorblack}{gray}{0}
\definecolor{ctcolorgray}{gray}{.5}
\definecolor{ctcolorgraylight}{gray}{.8}

\colorlet{ctcolorfooterpage}{ctcolorblack}
\colorlet{ctcolorfooterline}{ctcolormain}
\colorlet{ctcolorfootermark}{ctcolorblack}
\colorlet{ctcolorfootertitle}{ctcolormain}

\usepackage[automark]{scrlayer}% sets pagestyle scrheadings automatically

\newcommand*\pagenumberrule{%
  {\color{ctcolorfooterline}\rule[-90pt]{1.25pt}{100pt}}%
}
\DeclareNewLayer[
  foreground,
  oddpage,
  foot,
  contents={%
    \hfill
    \makebox[0pt][l]{%
      \pagenumberrule
      \hspace*{10pt}%
      \pagemark
    }%
  }
]{pagenumber.odd}
\DeclareNewLayer[
  clone=pagenumber.odd,
  contents={{\usekomafont{pageheadfoot}\hfill\headmark\hspace*{.75cm}}}%
]{headmark.odd}
\DeclareNewLayer[
  foreground,
  evenpage,
  foot,
  contents={%
    \makebox[0pt][r]{%
      \pagemark
      \hspace*{10pt}%
      \pagenumberrule
    }%
  }
]{pagenumber.even}
\DeclareNewLayer[
  clone=pagenumber.even,
  contents={{\usekomafont{pageheadfoot}\hspace*{.75cm}\headmark\hfill}}%
]{headmark.even}
\DeclarePageStyleByLayers{maincontentstyle}{%
  pagenumber.odd,pagenumber.even,%
  headmark.odd,headmark.even%
}
\DeclarePageStyleByLayers{plain}{%
  pagenumber.odd,pagenumber.even%
}

\setkomafont{pageheadfoot}{\color{ctcolorfootertitle}\tgherosfont\footnotesize}
\newkomafont{marknumber}{\color{ctcolorfootermark}\bfseries}
\setkomafont{pagenumber}{\color{ctcolorfooterpage}\tgherosfont\normalsize\bfseries}
\renewcommand\chaptermarkformat{{\usekomafont{marknumber}\chaptername\ \thechapter}\quad}
\renewcommand\sectionmarkformat{{\usekomafont{marknumber}\thesection}\quad}

\begin{document}
\pagestyle{maincontentstyle}
\blinddocument
\clearpage
\pagestyle{plain}
\blinddocument
\end{document}

相关内容