将 \toptitlemarks 和 \bottitlemarks 与任何计数器一起使用

将 \toptitlemarks 和 \bottitlemarks 与任何计数器一起使用

\toptitlemarks并且\bottitlemarks似乎不适用于随机计数器:

\documentclass[paper=a4,pagesize=pdftex]{scrbook}
\usepackage[pagestyles]{titlesec}
\usepackage{lipsum}

\newcounter{mycounter}

\newpagestyle{mystyle}{
  \setheadrule{.009pt}
  \sethead[\thepage][]
    [\toptitlemarks\themycounter---%
      \bottitlemarks\themycounter]%
    {\toptitlemarks\themycounter---%
      \bottitlemarks\themycounter}{}{\thepage}
}
\pagestyle{mystyle}

\begin{document}

\stepcounter{mycounter}
\markboth{\themycounter}{\themycounter}
\Huge\themycounter

\lipsum[2]

\stepcounter{mycounter}
\markboth{\themycounter}{\themycounter}
\Huge\themycounter

\lipsum[2]

\end{document}

生成:

顶部标题标记

有没有什么办法可以让它工作?

答案1

titleps软件包提供了自己的机制来处理新标记。您可以extramarks使用titleps软件包文档(第6. 加分):

\documentclass[paper=a4,pagesize=pdftex,twoside]{scrbook}
\usepackage[extramarks]{titleps}
\usepackage{lipsum}

\newcounter{mycounter}
\newmarkset{mycounter}
\newextramark*{mycounter}{mycounter}

\newpagestyle{mystyle}{
  \setheadrule{.009pt}
  \sethead[pg(\thepage)][]
    [(\topextramarks{mycounter}{\arabic{mycounter}}---%
      \botextramarks{mycounter}{\arabic{mycounter}})]%
    {(\topextramarks{mycounter}{\arabic{mycounter}}---%
      \botextramarks{mycounter}{\arabic{mycounter}})}{}{pg(\thepage)}
}
\pagestyle{mystyle}

\newcommand\updatemark{%
\stepcounter{mycounter}%
\extramark{mycounter}%
}
\begin{document}

\updatemark
\Huge\themycounter

\lipsum[2]

\updatemark
\Huge\themycounter

\lipsum[2]

\end{document}

在此处输入图片描述

相关内容