如何强制页面标记页脚显示在所有页面上,包括第一页?

如何强制页面标记页脚显示在所有页面上,包括第一页?

我正在尝试创建一个信件模板,并希望每一页都显示当前页面和总页数。但是,我无法让 koma 脚本\pagemark在第一页显示自定义。它总是从第二页开始。同时,要显示页眉仅有的在第二页,因为第一页有一个自定义页眉。

麦利来

\documentclass{scrlttr2}
\KOMAoption{paper}{a4}
\KOMAoption{firsthead}{yes}
\KOMAoption{firstfoot}{yes}

\usepackage{blindtext}

\pagestyle{myheadings}
\markright{\Ifkomavarempty{subject}{}{\centering\usekomavar{subject}}}
\renewcommand\pagemark{{\usekomafont{pagenumber}custom~pg~\thepage}}

\begin{document}

\setkomavar{fromname}{sender}
\setkomavar{fromaddress}{address}
\setkomavar{firsthead}{Custom firsthead}
% the following workaround doesn't work as intended
% because the bottom spacing of the 'firstfoot' is
% different from the regular footer distance
%%\setkomavar{firstfoot}{%
%%\centering\pagemark%
%%}
\setkomavar{date}{Date}
\setkomavar{subject}{Subject}

\begin{letter}{Addressee}
\opening{Hello}
World
\Blindtext
\closing{Cheers}

\end{letter}
\end{document}

自定义页面标记显示在第二页,但不显示在第一页:

呈现的文档

答案1

您可以添加\thispagestyle{plain}以下内容\opening{...},将第一页的页面样式从 更改emptyplain

\KOMAoption{firstfoot}{no}% <- changed: disable firstfoot
...
\opening{Hello}
\thispagestyle{plain}% <- added

请注意,您必须禁用firstfoot。另请参阅https://tex.stackexchange.com/a/578081/43317

例子:

\documentclass{scrlttr2}
%\KOMAoption{paper}{a4}% default
%\KOMAoption{firsthead}{yes}% default
\KOMAoption{firstfoot}{no}% <- changed: disable firstfoot
\usepackage{blindtext}

\pagestyle{myheadings}
\setkomavar{nexthead}{\parbox{\textwidth}{\centering\usekomavar{subject}}}
\renewcommand\pagemark{\usekomafont{pagenumber}{custom~pg~\thepage}}

\begin{document}

\setkomavar{fromname}{sender}
\setkomavar{fromaddress}{address}
\setkomavar{firsthead}{Custom firsthead}
\setkomavar{date}{Date}
\setkomavar{subject}{Subject}

\begin{letter}{Addressee}
\opening{Hello}
\thispagestyle{plain}% <- added

World
\Blindtext
\closing{Cheers}
\end{letter}
\end{document}

在此处输入图片描述

你也可以\opening使用

\KOMAoption{firstfoot}{no}% <- changed: disable firstfoot
...
\newcommand{\originalopening}{}
\let\originalopening\opening
\renewcommand{\opening}[1]{\originalopening{#1}\thispagestyle{plain}}

或者

\KOMAoption{firstfoot}{no}% <- changed: disable firstfoot
...
\usepackage{xpatch}
\xpatchcmd{\opening}{\thispagestyle{empty}}{\thispagestyle{plain}}{}{\PatchFailed}

在序言中。

例子:

\documentclass{scrlttr2}
%\KOMAoption{paper}{a4}% default
%\KOMAoption{firsthead}{yes}% default
\KOMAoption{firstfoot}{no}% <- changed: disable firstfoot
\usepackage{blindtext}

\pagestyle{myheadings}
\setkomavar{nexthead}{\parbox{\textwidth}{\centering\usekomavar{subject}}}
\renewcommand\pagemark{\usekomafont{pagenumber}{custom~pg~\thepage}}

\usepackage{xpatch}
\xpatchcmd{\opening}{\thispagestyle{empty}}{\thispagestyle{plain}}{}{\PatchFailed}

\begin{document}

\setkomavar{fromname}{sender}
\setkomavar{fromaddress}{address}
\setkomavar{firsthead}{Custom firsthead}
\setkomavar{date}{Date}
\setkomavar{subject}{Subject}

\begin{letter}{Addressee}
\opening{Hello}
World
\Blindtext
\closing{Cheers}
\end{letter}
\end{document}

结果和上面一样。

相关内容