花式标题自定义计数器参考

花式标题自定义计数器参考

我正在尝试排版一本圣经。页眉中应包含当前书名,然后是当前章节和当前诗句。“当前”是指该页中的下一页(或甚至是该页之前的最新一页;我还没有决定应该如何排版)。例如,如果一页的第一章和诗句是 2:15,则页眉应显示“<book> 2:15”。

显然我做错了,但输出结果非常不稳定,我甚至不知道从哪里开始。以下是一个例子:

\nonstopmode
\documentclass{book}
\usepackage{multicol}
\usepackage[left=1cm,right=1cm,top=1.1cm,bottom=1cm]{geometry}
\usepackage{fancyhdr}
\pagestyle{fancy}
\setcounter{chapter}{0}\newcounter{verse}
\def\book{}
\fancyhead[c]{\book \arabic{chapter}:\arabic{verse}}
\fancyfoot{}
\begin{document}
\def\book{Genesis}
\section*{Genesis}\begin{multicols}{2}\noindent\setcounter{chapter}{1}\textbf{\huge 1} In [the] beginning...
\setcounter{verse}{2}\textsuperscript{2}and the earth...\\
\setcounter{verse}{3}\textsuperscript{3}and God says...\\
\setcounter{verse}{4}\textsuperscript{4}And God sees...\\
\pagebreak
\setcounter{verse}{5}\textsuperscript{5}and God calls...\\
\setcounter{chapter}{2}\vspace{.2cm}\\\textbf{\huge 2} \setcounter{verse}{1}And the heavens...\\
\setcounter{verse}{2}\textsuperscript{2}and God completes...\\
\setcounter{chapter}{3}\vspace{.2cm}\\\textbf{\huge 3} And the serpent...\\
\pagebreak
\setcounter{verse}{2}\textsuperscript{2}And the woman...\\
\setcounter{verse}{3}\textsuperscript{3}but from the...\\
\setcounter{verse}{4}\textsuperscript{4}And the serpent...\\
\setcounter{verse}{22}\textsuperscript{22}And Zillah, she also bears Tubal-Cain, an instructor of every craftsman in bronze and iron; and a sister of Tubal-Cain [is] Naamah. 
\setcounter{verse}{23}\textsuperscript{23}And Lamech says to his wives: “Adah and Zillah, hear my voice; Wives of Lamech, give ear [to] my saying: For I have slain a man for my wound,
\end{multicols}
\end{document}

我正在重复使用chapter计数器并创建一个新的计数器,verse\def\book{Genesis}。当我运行它时pdflatex,我预计第一页的标题可能是“Genesis 1:1”。相反,它是“Genesis3:4”。我可以想象标题是“0:0”(因为在呈现标题时,书、章和诗句可能尚未初始化),但它指的是书的最后一节。这表明 fancyhdr 包只在排版的最后获取引用,然后将它们复制到每一页??在整本《创世纪》的大背景下,结果更加令人困惑,但我将为您省去这些细节。

我如何让 fancyhdr 在标题中呈现这些变量的“当前”值?

答案1

您必须使用标记机制来执行此操作。最简单的方法是创建一个用于开始一节的宏(这也可以减少输入)并在该宏中设置标记。

这是一个开始。

编辑:清理宏。我把 放在\vspace中,在章节和诗句的开头\startchapter放了一些\par和(你可以改为设置为)。还填满了一页,以显示下一章从页面顶部开始的效果。\noindents\parindent0pt

\documentclass{book}
\usepackage{multicol}
\usepackage[left=1cm,right=1cm,top=1.1cm,bottom=1cm]{geometry}
\usepackage{fancyhdr}
\pagestyle{fancy}
\setcounter{chapter}{0}\newcounter{verse}
\def\book{}
\fancyhead{}
\fancyhead[c]{\rightmark}
\fancyfoot{}
\newcommand{\startchapter}[1]{%
  \setcounter{chapter}{#1}%
  \vspace{.2cm}\par\noindent\textbf{\huge #1}%
  \markright{\book\ \thechapter:1}%
}
\newcommand{\Verse}[1]{%
  \noindent\textsuperscript{#1}%
  \markright{\book\ \thechapter:#1}%
}
\begin{document}
\def\book{Genesis}
\section*{Genesis}
\begin{multicols}{2}
\startchapter{1}
In [the] beginning...
\Verse{2}and the earth...\\
\Verse{3}and God says...\\[22cm]
\Verse{4}And God sees...\\[22cm]
\Verse{5}and God calls...\\[22cm]
\startchapter{2}
And the heavens...\\
\Verse{2}and God completes...\\
\startchapter{3}
And the serpent...\\
\newpage
\Verse{2}And the woman...\\
\Verse{3}but from the...\\
\Verse{4}And the serpent...\\
\Verse{22}And Zillah, she also bears Tubal-Cain, an instructor of every craftsman in bronze and iron; and a sister of Tubal-Cain [is] Naamah. 
\Verse{23}And Lamech says to his wives: “Adah and Zillah, hear my voice; Wives of Lamech, give ear [to] my saying: For I have slain a man for my wound,
\end{multicols}
\end{document}

在此处输入图片描述

这是原始图片,页面顶部有创世纪 1:5。

在此处输入图片描述

相关内容