标题、第一个和最后一个组合中的双计数器

标题、第一个和最后一个组合中的双计数器

对于一本包含主题和诗句的 2000 多页的书,我想在页眉上显示左页的第一诗句 # 和相应的主题 #。对于右页,我想显示最后一个主题 # 和相应的最后一诗句 #。

下面的代码适用于右侧的页面(最后一个主题和诗句)。对于左侧的页面,我遇到了一个问题:如果主题从上一页开始,但诗句在下一页继续,并且如果在同一页之后输入了新主题,那么我会从新主题中获取当前主题编号,而不是上一页的主题编号。(注意:主题编号通常嵌入在第 1 节段落中。它不在独立段落中)

我想要第 4 页:主题 2.3(我得到 3.3)有什么建议吗?该类是否memoir可以处理此策略(我使用过fancyhdr)?我还没有尝试过titleps,但是这个包可以做到吗?

\documentclass[12pt, twoside, openright]{memoir}
\usepackage{fancyhdr}
\usepackage{lipsum}

\newmarks\versemark
\newcounter{verses}

\newcommand{\versecounter}{%
    \leavevmode
    \stepcounter{verses}%
    \marks\versemark{\arabic{verses}}%
}

\newmarks\topicmark
\newcounter{topics}

\newcommand{\topicounter}{%
    \leavevmode
    \stepcounter{topics}%
    \marks\topicmark{\arabic{topics}}%
}

\newcommand{\firsttopicverse}{%
    \begingroup
    \edef\firstverse{\firstmarks\versemark}%
    \edef\firsttopic{\firstmarks\topicmark}%
    Topic \firsttopic .\firstverse
    \endgroup
}

\newcommand{\lasttopicverse}{%
    \begingroup
    \edef\lastverse{\botmarks\versemark}%
    \edef\lasttopic{\botmarks\topicmark}%

    Topic \lasttopic .\lastverse
\endgroup   
}

\pagestyle{fancy}
\fancyhf{}
\fancyhead[RE]{Should show 1st verse and current topic}
\fancyhead[LE]{\firsttopicverse}
\fancyhead[LO]{\lasttopicverse}
\fancyhead[RO]{Shows last topic \& verse}
\fancyfoot[LE,RO]{\thepage}

\begin{document}
    \chapter{Let's Talk About Topics}

    \topicounter
    {\Large{Topic \# \thetopics}}

    \versecounter
    {\textbf{\theverses.} }
    \lipsum[\theverses]
    \par

    \versecounter
    {\textbf{\theverses.} }
    \lipsum[\theverses]
    \par

    \versecounter
    {\textbf{\theverses.} }
    \lipsum[\theverses]
    \par
\pagebreak

    \versecounter
    {\textbf{\theverses.} }%
    \lipsum[\theverses]%
    \par
    \setcounter{verses}{0}
    \topicounter%
    {\Large{Topic \# \thetopics}}\\
    \versecounter
{\textbf{\theverses.} }
\lipsum[\theverses]
\par
\versecounter
{\textbf{\theverses.} }
\lipsum[\theverses]
\par
\pagebreak
\versecounter
{\textbf{\theverses.} }
\lipsum[\theverses]
\par
\par 
    \setcounter{verses}{0}
\topicounter
{\Large{Topic \# \thetopics}}

\versecounter
{\textbf{\theverses.} }
\lipsum[\theverses]
\par
\par 

\setcounter{verses}{0}
\topicounter
{\Large{Topic \# \thetopics}}
\versecounter
{\textbf{\theverses.} }
\lipsum[\theverses]
\par
\end{document}

答案1

假设您要避免在“主题 X”标题和下一节经文之间出现分页符,那么您可以简单地将所有内容放在该节经文的标记中:

\documentclass[12pt, twoside, openright]{memoir}
\usepackage{fancyhdr}
\usepackage{lipsum}


\newcommand{\versecounter}{%
    \leavevmode
    \stepcounter{verses}%
    \marks\versemark{Topic~\arabic{topics}.\arabic{verses}}%
}

\newmarks\topicmark
\newcounter{topics}

\newmarks\versemark
\newcounter{verses}[topics] %reset with topics counter

\newcommand{\topicounter}{%
    \leavevmode
    \stepcounter{topics}}

\newcommand{\firsttopicverse}{%
    \firstmarks\versemark}

\newcommand{\lasttopicverse}{\botmarks\versemark}

\pagestyle{fancy}
\fancyhf{}
\fancyhead[RE]{Should show 1st verse and current topic}
\fancyhead[LE]{\firsttopicverse}
\fancyhead[LO]{\lasttopicverse}
\fancyhead[RO]{Shows last topic \& verse}
\fancyfoot[LE,RO]{\thepage}

\begin{document}
    \chapter{Let's Talk About Topics}

    \topicounter
    {\Large{Topic \# \thetopics}}

    \versecounter
    {\textbf{\theverses.} }
    \lipsum[\theverses]
    \par

    \versecounter
    {\textbf{\theverses.} }
    \lipsum[\theverses]
    \par

    \versecounter
    {\textbf{\theverses.} }
    \lipsum[\theverses]
    \par
\pagebreak

    \versecounter
    {\textbf{\theverses.} }%
    \lipsum[\theverses]%
    \par
    \topicounter%
    {\Large{Topic \# \thetopics}}\\
    \versecounter
{\textbf{\theverses.} }
\lipsum[\theverses]
\par
\versecounter
{\textbf{\theverses.} }
\lipsum[\theverses]
\par
\pagebreak
\versecounter
{\textbf{\theverses.} }
\lipsum[\theverses]
\par
\par
\topicounter
{\Large{Topic \# \thetopics}}

\versecounter
{\textbf{\theverses.} }
\lipsum[\theverses]
\par
\par

\topicounter
{\Large{Topic \# \thetopics}}
\versecounter
{\textbf{\theverses.} }
\lipsum[\theverses]
\par
\end{document}

答案2

我不会使用fancyhdrwith,memoir因为它有自己的内置设置。因此,以下是 Ulrikes 针对memoir-only 标题做出的调整

\documentclass[12pt, twoside, openright]{memoir}
\usepackage{lipsum}


\newcommand{\versecounter}{%
    \leavevmode
    \stepcounter{verses}%
    \marks\versemark{Topic~\arabic{topics}.\arabic{verses}}%
}

\newmarks\topicmark
\newcounter{topics}

\newmarks\versemark
\newcounter{verses}[topics] %reset with topics counter

\newcommand{\topicounter}{%
    \leavevmode
    \stepcounter{topics}}

\newcommand{\firsttopicverse}{%
    \firstmarks\versemark}

\newcommand{\lasttopicverse}{\botmarks\versemark}

\makepagestyle{hpcolos}
\makeoddfoot{hpcolos}{}{}{\thepage}
\makeevenfoot{hpcolos}{\thepage}{}{}
\makeoddhead{hpcolos}{\lasttopicverse}{}{Shows last topic \& verse}
\makeevenhead{hpcolos}{\firsttopicverse}{}{Should show 1st verse and current topic}
\pagestyle{hpcolos}


\begin{document}
    \chapter{Let's Talk About Topics}

    \topicounter
    {\Large{Topic \# \thetopics}}

    \versecounter
    {\textbf{\theverses.} }
    \lipsum[\theverses]
    \par

    \versecounter
    {\textbf{\theverses.} }
    \lipsum[\theverses]
    \par

    \versecounter
    {\textbf{\theverses.} }
    \lipsum[\theverses]
    \par
\pagebreak

    \versecounter
    {\textbf{\theverses.} }%
    \lipsum[\theverses]%
    \par
    \topicounter%
    {\Large{Topic \# \thetopics}}\\
    \versecounter
{\textbf{\theverses.} }
\lipsum[\theverses]
\par
\versecounter
{\textbf{\theverses.} }
\lipsum[\theverses]
\par
\pagebreak
\versecounter
{\textbf{\theverses.} }
\lipsum[\theverses]
\par
\par
\topicounter
{\Large{Topic \# \thetopics}}

\versecounter
{\textbf{\theverses.} }
\lipsum[\theverses]
\par
\par

\topicounter
{\Large{Topic \# \thetopics}}
\versecounter
{\textbf{\theverses.} }
\lipsum[\theverses]
\par
\end{document}

相关内容