在尝试扩展 Simon Dispa 的答案以在索引中的某些点添加垂直间距时---发生了一件奇怪的事情

在尝试扩展 Simon Dispa 的答案以在索引中的某些点添加垂直间距时---发生了一件奇怪的事情

这篇文章旨在扩展 Simon Dispaa 的回答 为 Idxlayout 规定一定的垂直间距

考虑 MWE

\documentclass{book}
\usepackage{imakeidx}
\let\cleardoublepage\clearpage
\makeindex
\usepackage{idxlayout}
\usepackage{xcolor}

%\newcommand{\beforeheading}{10ex}% <<<<<<<<<<<<<<<<<
\newcommand{\beforeheadspace}{.3ex}% <<<<<<<<<<<<<<<<<
\newcommand{\beforesubheadspace}{.2ex}% <<<<<<<<<<<<<<<<<

%\renewcommand\item{\vspace*{\beforeheading}\par} % added <<<<<
\renewcommand\subitem{\vspace*{\beforeheadspace}\par\hangindent 40pt \hspace*{20pt}} % added <<<<<
\renewcommand\subsubitem{\vspace*{\beforesubheadspace}\par\hangindent 40pt \hspace*{30pt}} % added <<<<<

\begin{document}
    \large
    
    Some words.\index{VON GOETHE@\textbf{VON GOETHE'S \textit{FAUST}}!1@\textbf{\color{red}{Wagner}}!{Alack"! when a poor wight is so confined Amid his books, shut up from all mankind, And sees the world scarce on a holiday, As through a telescope and far away---}}
    \index{VON GOETHE@\textbf{VON GOETHE'S \textit{FAUST}}!1@\textbf{\color{red}{Wagner}}!{How may he hope, with nicely tempered skill, To bend the hearts he knows not to his will?}}
    
    More words.\index{VON GOETHE@\textbf{VON GOETHE'S \textit{FAUST}}!2@\textbf{\color{red}{Faust}}!{Be thine to seek the honest gain, No shallow-tinkling fool"! Sound sense finds utterance for itself, Without the critic's rule.}}
    \index{VON GOETHE@\textbf{VON GOETHE'S \textit{FAUST}}!2@\textbf{\color{red}{Faust}}!{If clear your thought, and your intention true, What need to hunt for words with much ado? The trim orations your fine speaker weaves, Crisping light shreds of thought for shallow minds, Are unrefreshing as the foggy winds That whistle through the sapless autumn leaves.}}
    
    A third set of words.\index{VON VON GOETHE@\textbf{GOETHE'S \textit{FAUST}}!1@\textbf{\color{red}{Wagner}}!{Alack"! when a poor wight is so confined Amid his books, shut up from all mankind, And sees the world scarce on a holiday, As through a telescope and far away---}}
        
    \idxlayout{columns=1}
    \printindex
\end{document}

产生输出

在此处输入图片描述

现在,我想将标题(歌德的浮士德)及其后续内容设置在当前位置的稍下方。

并且,为了模仿 Simon Dispa 的方法,我认为我应该在序言中引入以下内容:

\renewcommand\item{\vspace*{\beforeheading}\par} % added <<<<<

\renewcommand\item{\vspace*{\beforeheading}\par} % added <<<<<

但是唉,当我在上面的 MWE 中注释掉这两个命令时,什么也没有发生。

然而,当我修改索引条目,使第一个标题为“GOETHE'S FAUST”,第二个标题为“VON GOETHE"S FAUST”时——一件奇怪的事情发生了--- 我毫不费力就得到了我想要的东西;即

\documentclass{book}
\usepackage{imakeidx}
\let\cleardoublepage\clearpage
\makeindex
\usepackage{idxlayout}
\usepackage{xcolor}

%\newcommand{\beforeheading}{10ex}% <<<<<<<<<<<<<<<<<
\newcommand{\beforeheadspace}{.3ex}% <<<<<<<<<<<<<<<<<
\newcommand{\beforesubheadspace}{.2ex}% <<<<<<<<<<<<<<<<<

%\renewcommand\item{\vspace*{\beforeheading}\par} % added <<<<<
\renewcommand\subitem{\vspace*{\beforeheadspace}\par\hangindent 40pt \hspace*{20pt}} % added <<<<<
\renewcommand\subsubitem{\vspace*{\beforesubheadspace}\par\hangindent 40pt \hspace*{30pt}} % added <<<<<

\begin{document}
    \large
    
    Some words.\index{GOETHE@\textbf{GOETHE'S \textit{FAUST}}!1@\textbf{\color{red}{Wagner}}!{Alack"! when a poor wight is so confined Amid his books, shut up from all mankind, And sees the world scarce on a holiday, As through a telescope and far away---}}
    \index{GOETHE@\textbf{GOETHE'S \textit{FAUST}}!1@\textbf{\color{red}{Wagner}}!{How may he hope, with nicely tempered skill, To bend the hearts he knows not to his will?}}
    
    More words.\index{GOETHE@\textbf{GOETHE'S \textit{FAUST}}!2@\textbf{\color{red}{Faust}}!{Be thine to seek the honest gain, No shallow-tinkling fool"! Sound sense finds utterance for itself, Without the critic's rule.}}
    \index{VON GOETHE@\textbf{VON GOETHE'S \textit{FAUST}}!2@\textbf{\color{red}{Faust}}!{If clear your thought, and your intention true, What need to hunt for words with much ado? The trim orations your fine speaker weaves, Crisping light shreds of thought for shallow minds, Are unrefreshing as the foggy winds That whistle through the sapless autumn leaves.}}
    
    A third set of words.\index{VON GOETHE@\textbf{VON GOETHE'S \textit{FAUST}}!1@\textbf{\color{red}{Wagner}}!{Alack"! when a poor wight is so confined Amid his books, shut up from all mankind, And sees the world scarce on a holiday, As through a telescope and far away---}}
        
    \idxlayout{columns=1}
    \printindex
\end{document}

产生我正在寻找的东西---

在此处输入图片描述

问题:(一)是什么原因造成的第二次(期望的)出现?(ii)我怎样才能独立于标题的具体名称而始终生成它?

答案1

@索引条目根据-command 参数左边的内容按字母顺序/字典顺序排序\index

属于同一字母/符号的条目被分组在一起。

属于一个字母/符号的条目组与属于另一个字母/符号的条目组通过标记分开\indexspace

例如,在 .ind 文件中,你会看到类似

\begin{theindex}
[...]
%%% This belongs to "T":
\item Tim, 1
\item Tom, 2
%%%%%%%%%%%%%%%%%%%%%%%%
\indexspace 
%%%%%%%%%%%%%%%%%%%%%%%%
%%% This belongs to "U":
\item Ulrich, 2
\item Ulysses, 3
%%%%%%%%%%%%%%%%%%%%%%%%
\indexspace 
%%%%%%%%%%%%%%%%%%%%%%%%
%%% This belongs to "V":
\item Vernon, 1
\item Virgil, 7
[...]
\end{theindex}

在您的第一个例子中,事物按“VON GOETHE”或“VON VON GOETHE”排序。

\indexspace因此,所有内容都属于字母/符号“V”的索引条目组,因此条目之间没有标记。

在第二个示例中,有些东西归类到“GOETHE”下,其他东西归类到“VON GOETHE”下。因此,有些东西最终归类到属于字母/符号“G”的索引条目组,而其他东西最终归类到属于字母/符号“V”的索引条目组。归类到字母/符号“G”下的事物组与归类到字母/符号“V”下的事物组之间以 分隔\indexspace
这就是为什么在第二个示例中,您会看到归类到“GOETHE”下并最终归类到属于字母/符号“G”的索引条目组的条目与归类到“VON GOETHE”下并最终归类到属于字母/符号“V”的索引条目组的条目之间存在垂直空格。


我不建议\item在序言中重新定义:

重新定义可能会影响基于list/trivlist的不能确保其自身定义的环境\item

除此之外, 的重新定义\item对索引没有影响,因为该重新定义被 -environment 覆盖,而theindex又被写入 .ind 文件,该文件的读取和处理又由 触发\printindex。您可以通过将其添加到索引条目的文本来检查这一点。这将使它进入 .ind 文件并在终端/控制台上显示LaTeX 排版索引时\show\item命令的含义。\item


如果您希望在所有顶层索引条目之前进行垂直跳过,而不仅仅是为了将属于一个字母/符号的一组索引条目与属于另一个字母/符号的一组索引条目分开,则以下方法可能会奏效:

\documentclass{book}
\usepackage{imakeidx}
\let\cleardoublepage\clearpage
\makeindex
\usepackage{idxlayout}
\usepackage{xcolor}

\begin{document}
    \large

    Some words.\index{VON GOETHE@\textbf{VON GOETHE'S \textit{FAUST}}!1@\textbf{\color{red}{Wagner}}!Alack"! when a poor wight is so confined Amid his books, shut up from all mankind, And sees the world scarce on a holiday, As through a telescope and far away---}
    \index{VON GOETHE@\textbf{VON GOETHE'S \textit{FAUST}}!1@\textbf{\color{red}{Wagner}}!How may he hope, with nicely tempered skill, To bend the hearts he knows not to his will?}
    
    More words.\index{VON GOETHE@\textbf{VON GOETHE'S \textit{FAUST}}!2@\textbf{\color{red}{Faust}}!Be thine to seek the honest gain, No shallow-tinkling fool"! Sound sense finds utterance for itself, Without the critic's rule.}
    \index{VON GOETHE@\textbf{VON GOETHE'S \textit{FAUST}}!2@\textbf{\color{red}{Faust}}!If clear your thought, and your intention true, What need to hunt for words with much ado? The trim orations your fine speaker weaves, Crisping light shreds of thought for shallow minds, Are unrefreshing as the foggy winds That whistle through the sapless autumn leaves.}
    
    A third set of words.\index{VON VON GOETHE@\textbf{GOETHE'S \textit{FAUST}}!1@\textbf{\color{red}{Wagner}}!Alack"! when a poor wight is so confined Amid his books, shut up from all mankind, And sees the world scarce on a holiday, As through a telescope and far away---}
        
    \idxlayout{columns=1}
    \begingroup
    \makeatletter
    \long\def\indexspace{\par}%
    \@ifdefinable\saved@idxitem{\let\saved@idxitem=\@idxitem}%
    \long\def\@idxitem{\par\vspace{\ila@initsep}\saved@idxitem}%
    \long\def\subitem{\saved@idxitem\hspace*{\ila@subindent}}%
    \long\def\subsubitem{\saved@idxitem\hspace*{\ila@subsubindent}}%
    \makeatother
    \printindex
    \endgroup

\end{document}

在此处输入图片描述

在此处输入图片描述

这种排序顺序的依据是,按字典顺序排列为“VON GOETHE”的条目位于按“VON VON GOETHE”排序的条目之前


这是一个变体,您可以在索引的项目/子项目/子子项目之前指定垂直跳过:

\documentclass{book}
\usepackage{imakeidx}
\let\cleardoublepage\clearpage
\makeindex
\usepackage{idxlayout}
\usepackage{xcolor}

\begin{document}
    \large

    Some words.\index{VON GOETHE@\textbf{VON GOETHE'S \textit{FAUST}}!1@\textbf{\color{red}{Wagner}}!Alack"! when a poor wight is so confined Amid his books, shut up from all mankind, And sees the world scarce on a holiday, As through a telescope and far away---}
    \index{VON GOETHE@\textbf{VON GOETHE'S \textit{FAUST}}!1@\textbf{\color{red}{Wagner}}!How may he hope, with nicely tempered skill, To bend the hearts he knows not to his will?}
    
    More words.\index{VON GOETHE@\textbf{VON GOETHE'S \textit{FAUST}}!2@\textbf{\color{red}{Faust}}!Be thine to seek the honest gain, No shallow-tinkling fool"! Sound sense finds utterance for itself, Without the critic's rule.}
    \index{VON GOETHE@\textbf{VON GOETHE'S \textit{FAUST}}!2@\textbf{\color{red}{Faust}}!If clear your thought, and your intention true, What need to hunt for words with much ado? The trim orations your fine speaker weaves, Crisping light shreds of thought for shallow minds, Are unrefreshing as the foggy winds That whistle through the sapless autumn leaves.}
    
    A third set of words.\index{VON VON GOETHE@\textbf{GOETHE'S \textit{FAUST}}!1@\textbf{\color{red}{Wagner}}!Alack"! when a poor wight is so confined Amid his books, shut up from all mankind, And sees the world scarce on a holiday, As through a telescope and far away---}
        
    \idxlayout{columns=1}
    \begingroup
    \makeatletter
    \long\def\indexspace{\par}%
    \@ifdefinable\saved@idxitem{\let\saved@idxitem=\@idxitem}%
    \long\def\@idxitem{\if@nobreak\par\else\par\addvspace{\beforeitem}\fi\saved@idxitem}%
    \long\def\subitem{\if@nobreak\par\else\par\addvspace{\beforesubitem}\fi
                      \setlength{\hangindent}{\ila@hangindent}\hspace*{\ila@subindent}}%
    \long\def\subsubitem{\if@nobreak\par\else\par\addvspace{\beforesubsubitem}\fi
                         \setlength{\hangindent}{\ila@hangindent}\hspace*{\ila@subsubindent}}%
    % Modify these macros for changing vertical skips:
    \newcommand\beforeitem{2\ila@initsep}% <-vertical space before VON GOETHE'S FAUST / GOETHE'S FAUST
    \newcommand\beforesubitem{1\ila@initsep}% <-vertical space before WAGNER / FAUST
    \newcommand\beforesubsubitem{0.5\ila@initsep}% <-vertical space before quotes and page numbers
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \makeatother
    \printindex
    \endgroup

\end{document}

在此处输入图片描述

在此处输入图片描述

相关内容