使用带层次结构的索引时出现空行。如何避免这种情况?

使用带层次结构的索引时出现空行。如何避免这种情况?

对于一本关于蝴蝶和飞蛾的德语书籍,我想准备一份毛毛虫生长的植物的索引。不幸的是,德语命名法由混合的单个术语和组合术语组成:Buche(山毛榉)和 Hain-Buche(鹅耳枥)。我想按 Buche !Hain- !蝴蝶的顺序排列。当使用 Buche 时没有第二个参数 splitindex(以及 makeindex)会失败。所以我添加了 \leer;然而,这会增加一个空行。

\documentclass[11pt,a5paper]{scrbook}
\usepackage[russian,ngerman]{babel}
\usepackage{splitidx,xparse}
\newindex[Raupenwirtspfanzen]{pfl}
\newcommand{\leer}{\hspace*{0.1mm}}
\newcommand{\PFL}[3]{#2#1\sindex[pfl]{#1!#2!#3}}
\usepackage{hyperref}
\begin{document}
\PFL{Buche}{\leer}{Pieris rapae}
\PFL{Buche}{Hain-}{Pieris rapae}
 
\printindex*
\end{document}

使用pdflatex和splitindex进行编译,如何去掉“Buche”后面的空行?

(顺便说一句,这在 docbook xml 中很容易实现。您只需将第二个参数留空。)

答案1

您在示例中忘记了 \makeindex。您可以重新定义 \subitem 以向前看,并且如果检测到 \relax 则不执行任何操作:

\documentclass[11pt,a5paper]{scrbook}
\usepackage[russian,ngerman]{babel}
\usepackage{splitidx,xparse}
\newindex[Raupenwirtspfanzen]{pfl}
\newcommand{\PFL}[3]{#2#1\sindex[pfl]{#1!#2!#3}}
\usepackage{hyperref}
\makeindex
\ExplSyntaxOn\makeatletter
\renewcommand*\subitem{\peek_meaning_ignore_spaces:NF\relax{\@idxitem \hspace*{20\p@}}}
\ExplSyntaxOff\makeatother
\begin{document}
\PFL{Buche}{\relax}{Pieris rapae}
\PFL{Buche}{Hain-}{Pieris rapae}

\printindex*
\end{document}

在此处输入图片描述

相关内容