multicol 文档中的 titleps 底部标记略有偏离

multicol 文档中的 titleps 底部标记略有偏离

我正在使用 XeLaTeX 排版圣经文本。我需要在页眉中打印书籍、章节和诗句引用,因此我使用带有 extramarks 选项的 titleps 来为这些文本划分定义自定义标记集。此外,我想对介绍性材料使用单列布局,对圣经材料使用双列布局,因此我加入了 multicol 包。

我注意到,如果诗句足够短,那么 multicol 似乎会在计算多页底部标记(在本例中为最后一节诗句编号)时出错。我在下面附上了一张此图像(由我的最小工作示例生成)。

最小工作示例截图

我已将 .tex 文件和 .sty 文件精简为下面的最小形式。

mwe.sty

%Declare the package that this file will produce, along with its formal name:
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{mwe}[2020/03/13 Minimal Working Example]

%Include support for multi-column text layout:
\RequirePackage{multicol}
\raggedcolumns

%Include support for page header styles:
\RequirePackage[extramarks]{titleps}

%Page styles and macros:
\newcommand{\BookTitle}{}
\newcommand{\ChapterTitle}{}
\newcommand{\VerseTitle}{}
\newcounter{Book}
\newcounter{Chapter}
\newcounter{Verse}
\newmarkset{Book}
\newmarkset{Chapter}
\newmarkset{Verse}
\newextramark{Book}{\BookTitle}
\newextramark{Chapter}{\ChapterTitle}
\newextramark{Verse}{\VerseTitle}
\newextramark*{Book}{Book}
\newextramark*{Chapter}{Chapter}
\newextramark*{Verse}{Verse}
\newcommand{\Book}[1]{%
    %Set the page style:
    \pagestyle{BookPage}%
    %Set the current book title to the argument of the \Book macro and reset the chapter and verse titles:
    \renewcommand\BookTitle{#1}%
    \renewcommand\ChapterTitle{1}%
    \renewcommand\VerseTitle{1}%
    %Increment the book counter, and reset the chapter and verse counters:
    \stepcounter{Book}%
    \setcounter{Chapter}{1}%
    \setcounter{Verse}{1}%
    \preextramark{Book}%
    \preextramark{Chapter}%
    \preextramark{Verse}%
    \extramark{Book}%
    \extramark{Chapter}%
    \extramark{Verse}%
}
\newcommand{\PreChapterSpace}{% adds non-breaking space before a new chapter marker
    \hspace{0.5em}
}
\newcommand{\Chapter}[1]{%
    %Set the chapter title to the specified value and reset the verse title:
    \renewcommand\ChapterTitle{#1}%
    \renewcommand\VerseTitle{1}%
    %Set the chapter counter to the specified value, and reset the verse counter:
    \setcounter{Chapter}{#1}%
    \setcounter{Verse}{1}%
    %Update the extra marks for references in the heading:
    \preextramark{Chapter}%
    \preextramark{Verse}%
    {\textbf{\ChapterTitle\,:\,\VerseTitle}}\hspace*{0.5em}
    \extramark{Chapter}%
    \extramark{Verse}%
}
\newcommand{\PreVerseSpace}{% adds non-breaking space before a new verse marker
    \hspace{0.5em}
}
\newcommand{\Verse}[1]{%
    \renewcommand\VerseTitle{#1}%
    \setcounter{Verse}{#1}%
    %Update the extra marks for references in the heading:
    \preextramark{Chapter}%
    \preextramark{Verse}%
    \ifnum#1 > 1{%
        {\textbf{#1}}\hspace*{0.5em}
    }\fi%
    \extramark{Chapter}%
    \extramark{Verse}%
}

%Macro for collapsing reference ranges as needed:
\newcommand{\RefRange}{%
    %We need to declare these here to check for their equality with the current chapter and verse titles;
    %otherwise, headers for one-verse pages will be printed as ranges instead of a single verse references:
    \firstextramarks{Chapter}%
    \firstextramarks{Verse}%
    %Check if the current chapter matches the first chapter on the page:
    \ifsamemark{\firstextramarks{Chapter}}{\ChapterTitle}{%
        %Then check if the current chapter matches the bottom chapter on the page (essentially, we're checking if the first and last chapter marks are equal):
        \ifsamemark{\botextramarks{Chapter}}{\ChapterTitle}{%
            %Check if the current verse matches that of the first verse on the page:
            \ifsamemark{\firstextramarks{Verse}}{\VerseTitle}{%
                %Then check if the current verse matches the bottom verse on the page (essentially, we're checking if the first and last verse marks are equal):
                \ifsamemark{\botextramarks{Verse}}{\VerseTitle}{%
                    %If the chapters and verses match, then the page consists of a single verse; use its reference:
                    \firstextramarks{Chapter}\ChapterTitle:\firstextramarks{Verse}\VerseTitle%
                }{%
                    %If there is no match, then use one chapter and the verse range:
                    \firstextramarks{Chapter}\ChapterTitle:\firstextramarks{Verse}\VerseTitle--\botextramarks{Verse}\VerseTitle%
                }%
            }{%
                %If there is no match, then use one chapter and the verse range:
                \firstextramarks{Chapter}\ChapterTitle:\firstextramarks{Verse}\VerseTitle--\botextramarks{Verse}\VerseTitle%
            }%
        }{%
            %If there is no match, then use the entire reference range:
            \firstextramarks{Chapter}\ChapterTitle:\firstextramarks{Verse}\VerseTitle--\botextramarks{Chapter}\ChapterTitle:\botextramarks{Verse}\VerseTitle%
        }%
    }{%
        %If there is no match, then use the entire reference range:
        \firstextramarks{Chapter}\ChapterTitle:\firstextramarks{Verse}\VerseTitle--\botextramarks{Chapter}\ChapterTitle:\botextramarks{Verse}\VerseTitle%
    }%
}

%Page style:
\makepagestyle{BookPage}
\makeevenhead{BookPage}{\RefRange}{\topextramarks{Book}\BookTitle}{}
\makeevenfoot{BookPage}{\thepage}{}{} %Page number on left in footer on even pages
\makeoddhead{BookPage}{}{\topextramarks{Book}\BookTitle}{\RefRange}
\makeoddfoot{BookPage}{}{}{\thepage} %Page number on right in footer on odd pages

%Define a macro to generate consecutive verses of sample text:
\newcommand{\blindtext}[1]{%use a default value of 1 to coerce the argument to a number
    \newcounter{i}
    \setcounter{i}{1}%
    \loop%
    \Verse{\thei}In the beginning, God created the heavens and the earth.\PreVerseSpace{}%
    \stepcounter{i}%
    \ifnum\numexpr\value{i}-1<#1%
    \repeat%
}

%Finally, close the input:
\endinput
mwe.tex

\documentclass[twoside, 12pt]{memoir}
\usepackage{../sty/mwe}
\begin{document}
\Book{MWE}
\begin{multicols}{2}
\noindent
\normalsize
\Chapter{1}\blindtext{200}\par
\pagebreak
\end{multicols}
\end{document}

(很抱歉,最小的 .sty 文件仍然有 100 行多;可能有更简洁的方法来编写我编写的宏,但我正在学习如何使用 titleps。)

我查看了 titleps 的文档,唯一能找到的相关评论是,一些使用 \markboth 和 \markleft 命令的类可能无法与 titleps 一起正常工作;具体来说,“双列布局需要 David Carlisle 的 fix2col 包”(第 2 页,第 1 页)。但据我所知,fix2col 中的补丁已合并到 LaTeX 中,使该包过时了。

multicol 手册在第 5.1 节详细讨论了该包对标记的处理,但讨论相当技术性,我跟不上。我没有看到任何关于 titleps 的提及,所以我不知道 multicol 是否像处理标准标记集那样处理“额外标记”标记集。

解决方案是否像调整 multicol 使用的惩罚参数一样简单?任何有关如何修复标题中的章节引用的建议都将不胜感激!

答案1

非常感谢 Ulrike Fischer 为我指明了正确的方向!使用标准 LaTeX 命令 \markboth 和 \markright 以及 extramarks 包中的 \firstleftmark、\firstrightmark、\lastleftmark 和 \lastrightmark 命令,我能够使 MWE 正常工作,并使我的代码更紧凑!下面更新的 .sty 文件现在只有 80 行!

mwe.sty

%Declare the package that this file will produce, along with its formal name:
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{mwe}[2020/03/13 Minimal Working Example]

%Include support for multi-column text layout:
\RequirePackage{multicol}
\raggedcolumns

%Include support for getting first and last marks:
\RequirePackage{extramarks}

%Define a macro that will be redefined with the current book title whenever it changes (for reference in the header):
\newcommand{\BookTitle}{}

\newcommand{\Book}[1]{%
    %Set the page style:
    \pagestyle{BookPage}%
    %Set the current book title:
    \renewcommand{\BookTitle}{#1}%
    %Reset the left (= chapter) and right (= verse) marks:
    \markboth{1}{1}%
}
\newcommand{\PreChapterSpace}{% adds (breakable) space before a new chapter marker
    \hspace{0.5em}
}
\newcommand{\Chapter}[1]{%
    %Set the current left (= chapter) mark and reset the right (= verse) mark:
    \markboth{#1}{1}%
    %Then typeset the chapter number:
    {\textbf{#1\,:\,}}%
}
\newcommand{\PreVerseSpace}{% adds (breakable) space before a new verse marker
    \hspace{0.5em}
}
\newcommand{\Verse}[1]{%
    %Set the current right (= verse) mark:
    \markright{#1}%
    %Then typeset the verse number:
    {\textbf{#1}}\hspace*{0.5em}
}

%Macro for collapsing reference ranges as needed:
\RequirePackage{ifthen}
\newcommand{\RefRange}{%
    %Check if the first chapter matches the last chapter on the page:
    \ifthenelse{\equal{\firstleftmark}{\lastleftmark}}{%
        %If the chapters match, then check if the first verse matches the last verse on the page:
        \ifthenelse{\equal{\firstrightmark}{\lastrightmark}}{%
            %If the verses match, then the page consists of a single verse; use its reference:
            \firstleftmark:\firstrightmark%
        }{%
            %If the verses do not match, then use one chapter and the verse range:
            \firstleftmark:\firstrightmark--\lastrightmark%
        }%
    }{%
        %If the chapters do not match, then use the entire reference range:
        \firstleftmark:\firstrightmark--\lastleftmark:\lastrightmark%
    }%
}

%Page style:
\makepagestyle{BookPage}
\makeevenhead{BookPage}{\RefRange}{\BookTitle}{}
\makeevenfoot{BookPage}{\thepage}{}{} %Page number on left in footer on even pages
\makeoddhead{BookPage}{}{\BookTitle}{\RefRange}
\makeoddfoot{BookPage}{}{}{\thepage} %Page number on right in footer on odd pages

%Define a macro to generate consecutive verses of sample text:
\newcounter{i}
\newcommand{\blindtext}[1]{%use a default value of 1 to coerce the argument to a number
    \setcounter{i}{1}%
    \loop%
    \Verse{\thei}In the beginning, God created the heavens and the earth.\PreVerseSpace{}%
    \stepcounter{i}%
    \ifnum\numexpr\value{i}-1<#1%
    \repeat%
}

%Finally, close the input:
\endinput

我能够使用以下 .tex 文件检查并确保 \RefRange 宏中的所有情况都已被涵盖:

mwe.tex

\documentclass[twoside, 12pt]{memoir}
\usepackage{../sty/mwe}
\begin{document}
\Book{MWE}
\begin{multicols}{2}
\noindent
\normalsize
\Chapter{1}\blindtext{2}\Chapter{2}\blindtext{84}\par
\pagebreak
\end{multicols}
\end{document}

相关内容