仅在 KOMAscript / classicthesis 中更改一页的页码

仅在 KOMAscript / classicthesis 中更改一页的页码

我碰到这个帖子将页码 4 更改为pi。建议的解决方案如下,它适用于回忆录文档类:

\documentclass{memoir}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{blindtext}

\makeatletter
\newcommand{\@weird}[1]{%
\ifnum#1< 4
\@arabic{#1}%
\else
\ifnum#1=4   
\texorpdfstring{\large$\pi$}{π}%
\else
\@arabic{\numexpr#1-1}%
\fi
\fi
}
\makeatother

\usepackage{hyperref}
\begin{document}
\frontmatter
\tableofcontents
\mainmatter
\clearpage
\pagenumbering{weird}
\chapter{First}
\blindtext[50]
\chapter{Second}
\blindtext[50]
\end{document}

我尝试了类似的样式classicthesis。我尝试将某些页码设为粗体,例如第 4 页,但以下 MWE 失败并显示我无法理解的错误消息。

\documentclass[%
    twoside, openright, titlepage, numbers=noenddot,%
    cleardoublepage=empty,%
]{scrreprt}

\PassOptionsToPackage{%
  dottedtoc,%
  eulerchapternumbers,
  floatperchapter, pdfspacing,%
  beramono,%
  a5paper,%
}{classicthesis}
\usepackage{classicthesis}

\usepackage{kantlipsum}

\makeatletter
\newcommand{\@weird}[1]{%
\ifnum#1=4   
\texorpdfstring{\textbf{4}}{4}%
\else
\@arabic{\numexpr#1-1}%
\fi
}
\makeatother

\begin{document}

% TOC
\pdfbookmark[1]{\contentsname}{tableofcontents}

\pagenumbering{weird}
\chapter{Chapter 1}
\kant[1-6]

\chapter{Chapter 2}
\kant[7-15]

\end{document}

我怎样才能使它工作classicthesis

答案1

classicthesis用途scrlayer-scrpage,因此您不需要对页码样式进行修改即可更改页码的字体。您只需使用\setkomafont

\documentclass[%
    twoside, openright, titlepage, numbers=noenddot,%
    cleardoublepage=empty,%
]{scrreprt}

\PassOptionsToPackage{%
  dottedtoc,%
  eulerchapternumbers,
  floatperchapter, pdfspacing,%
  beramono,%
  a5paper,%
}{classicthesis}
\usepackage{classicthesis}

\usepackage{kantlipsum}

\makeatletter
\setkomafont{pagenumber}{\ifnum \the\c@page=4 \bfseries\fi}
\makeatother

\begin{document}

% TOC
\pdfbookmark[1]{\contentsname}{tableofcontents}

\chapter{Chapter 1}
\kant[1-8]

\chapter{Chapter 2}
\kant[9-15]

\end{document}

顺便说一句:scrlayer-scrpageclassicthesis使用\pagemark页码。因此,作为替代方案,您可以重新定义\pagemark而不是\thepage更改页码的输出。这也会允许绝对奇怪的输出定义:

\documentclass[%
    twoside, openright, titlepage, numbers=noenddot,%
    cleardoublepage=empty,%
]{scrreprt}

\PassOptionsToPackage{%
  dottedtoc,%
  eulerchapternumbers,
  floatperchapter, pdfspacing,%
  beramono,%
  a5paper,%
}{classicthesis}
\usepackage{classicthesis}

\usepackage{graphics}
\usepackage{kantlipsum}

\makeatletter
\ExplSyntaxOn
\renewcommand*{\pagemark}{%
  \fp_set:Nn \l_tmpa_fp { 360 / \c@page }
  \rotatebox { \fp_to_int:N \l_tmpa_fp } { \usekomafont{pagenumber}{\thepage} }
}
\ExplSyntaxOff
\setkomafont{pagenumber}{\ifnum \the\c@page=3 $\pi$ \expandafter\@gobble\fi}% NOTE: You must not use \addtokomafon{pagenumber} after this definition!
\makeatother

\begin{document}

% TOC
\pdfbookmark[1]{\contentsname}{tableofcontents}

\chapter{Chapter 1}
\kant[1-8]

\chapter{Chapter 2}
\kant[9-15]

\end{document}

因此不需要定义 weird\thepage来得到奇怪的输出。

对于多个页码的特殊情况,使用 可能会更有意义\int_case:nn,例如

\setkomafont{pagenumber}
  {
    \int_case:nn { \c@page }
      {
        { 3 } { $\pi$ \use_none:n }
        { 5 } { \ensuremath }
        { 7 } { \bfseries } % \textbf would be possible but a font switch instead of a font command should be preferred
      }
  }

请注意,您必须将\ExplSyntaxOff示例中的 移到该命令后面:

\documentclass[%
    twoside, openright, titlepage, numbers=noenddot,%
    cleardoublepage=empty,%
]{scrreprt}

\PassOptionsToPackage{%
  dottedtoc,%
  eulerchapternumbers,
  floatperchapter, pdfspacing,%
  beramono,%
  a5paper,%
}{classicthesis}
\usepackage{classicthesis}

\usepackage{graphics}
\usepackage{kantlipsum}

\makeatletter
\ExplSyntaxOn
\renewcommand*{\pagemark}{%
  \fp_set:Nn \l_tmpa_fp { 360 / \c@page }
  \rotatebox { \fp_to_int:N \l_tmpa_fp } { \usekomafont{pagenumber}{\thepage} }
}
\setkomafont{pagenumber}
  {
    \int_case:nn { \c@page }
      {
        { 3 } { $\pi$ \use_none:n }
        { 5 } { \ensuremath }
        { 7 } { \bfseries } % \textbf would be possible but a font switch instead of a font command should be preferred
      }
  }
\ExplSyntaxOff
\makeatother

\begin{document}

% TOC
\pdfbookmark[1]{\contentsname}{tableofcontents}

\chapter{Chapter 1}
\kant[1-8]

\chapter{Chapter 2}
\kant[9-15]

\end{document}

LaTeX3 接口有关上述示例中使用的 l3 函数(和变量)的更多信息。

请注意,只有元素的最后一个字体更改pagenumber才允许作为带参数的命令。因为在这个例子中,\@gobble(或\use_none:n) 用于吃掉页码,如果页码是 3,则不应\addtokomafont{pagenumber}{…}在 之后使用\setkomafont{pagenumber}{…}

我认为重新定义\thepage才有意义,如果每一个用法应该改变,即,如果 ToC、LoT、LoF 和页面引用的条目也\pageref应该使用此输出。因此,对于 pi 的输出来说,这可能有意义,但恕我直言,更改字体没什么用。

答案2

如果你正在做一些奇怪的事情,无法通过简单的字体选择来吸收,你可以修改egreg 的回答适用于您的情况。

\documentclass[%
    twoside, openright, titlepage, numbers=noenddot,%
    cleardoublepage=empty,%
]{scrreprt}

\PassOptionsToPackage{%
  dottedtoc,%
  eulerchapternumbers,
  floatperchapter, pdfspacing,%
  beramono,%
  a5paper,%
}{classicthesis}
\usepackage{classicthesis}

\usepackage{kantlipsum}

\makeatletter
\newcommand{\@weird}[1]{%
\ifnum#1=4   
\texorpdfstring{\textbf{4}}{4}%
\else
\@arabic{\numexpr#1-1}%
\fi
}
\renewcommand*\mph@outputpage@hook{%
    \bgroup
    \let\@weird\@arabic % make \@weird the same as \@arabic, for the purposes of MPH
    \advance\c@page\m@ne
    \immediate\write\@auxout{%
        \string\mph@setcol{ii:\thepage}{\string\mph@nr}%
    }%
    \egroup
}
\makeatother

\begin{document}
% TOC
\pdfbookmark[1]{\contentsname}{tableofcontents}

\pagenumbering{weird}
\chapter{Chapter 1}
\kant[1-6]

\chapter{Chapter 2}
\kant[7-15]

\end{document}

相关内容