考虑以下代码:
\documentclass[openany]{book}
\usepackage{imakeidx}
\makeindex
\usepackage{idxlayout}
\begin{document}
\thispagestyle{empty}
\Large
This is a sentence. This is another \textbf{sentence}. \textbf{This} is too a sentence.
\vspace*{15pt}
This is a sentence. This is another \textbf{sentence}. \index{HEADING@\textbf{HEADING}! An index entry with a lot of words.} \index{HEADING@\textbf{HEADING}! A different index entry with some more words.} \textbf{This} is too a sentence. This is another sentence. This is a sentence.
\idxlayout{columns=1}
\printindex
\end{document}
第一页输出:
请注意第一段中句子之间的(预期)适当水平间距,尽管在代码中我在第二句和第三句之间插入了额外的空格。
评论:如果我在所述句子之间插入代码中的十个额外空格,我期望得到相同的输出。
现在,看看第二段的输出——特别是——在第二个和第三个空格之间插入的额外水平空格。代码中的不同之处在于——我插入了几个索引命令,这些命令在很多时候似乎对两个连续句子之间的水平间距没有任何影响。
但在这里,确实如此。
问题:谁能告诉我是什么原因导致了这种不良现象,有什么补救措施吗?也许更重要的是,是否有正确的方法来插入索引代码?在两个连续的索引命令之间留一个空格可以吗?还是应该像一个长命令一样连续插入而不中断?
笔记:我添加了粗体以强调视觉效果。无论是否使用粗体,都会发生所描述的现象。我用 编译代码lualatex
。
谢谢。
答案1
您观察到的间距并不取决于长索引条目,而只是取决于周围的空格\index{...}
数数作为输出中的空格。
我重复使用代码由 Marcin Woliński 编写它允许显示空间来说明发生了什么。
\documentclass{article}
\usepackage{makeidx}
\makeindex
\newcommand{\AND}{\unskip
\hskip 2pt plus 1pt minus 1pt
\cleaders\copy\ANDbox\hskip\wd\ANDbox
\hskip 2pt plus 1pt minus 1pt
\ignorespaces}
\newsavebox\ANDbox
\sbox\ANDbox{\textbullet}
\begin{document}
\catcode` =\active
\let =\AND
This is a sentence. %
This is another \textbf{sentence}. %
\textbf{This} is too a sentence.
\vspace*{15pt}
This is a sentence. %
This is another \textbf{sentence}. \index{a} \textbf{This} is too a sentence. %
This is another sentence. This is a sentence.
\vspace*{15pt}
This is a sentence. %
This is another \textbf{sentence}. \index{b} \index{c} \textbf{This} is too a sentence. %
This is another sentence. This is a sentence.
\end{document}
您可以看到,第二段中由于单个\index
命令而有两个空格,而第三段中有三个空格。
首先,没有空间索引单词和\index
命令之间。还请考虑空格可以允许换行,而换行又可以允许分页,这样您就会发现索引条目引用了不同的页面比它指向的单词更重要。
?的最佳位置是什么\index
?在您想要索引的单词前面,这还具有不允许连字符的好处。
\documentclass{article}
\usepackage[english]{babel}
\usepackage{makeidx}
\makeindex
\newcommand{\AND}{\unskip
\hskip 2pt plus 1pt minus 1pt
\cleaders\copy\ANDbox\hskip\wd\ANDbox
\hskip 2pt plus 1pt minus 1pt
\ignorespaces}
\newsavebox\ANDbox
\sbox\ANDbox{\textbullet}
\begin{document}
\catcode` =\active
\let =\AND
This is a sentence. %
This is another \textbf{sentence}. %
\textbf{This} is too a sentence.
\vspace*{15pt}
This is a sentence. %
This is another \index{a}\textbf{sentence}. \textbf{This} is too a sentence. %
This is another sentence. This is a sentence.
\vspace*{15pt}
This is a sentence. %
This is another \index{b}\index{c}\textbf{sentence}. \textbf{This} is too a sentence. %
This is another sentence. This is a sentence.
\end{document}
在困难的段落情况下,你可以决定怎么做,也许使用
\index{entry}\nolinebreak\hspace{0pt}longwordwithindexthatmustbehyphenated
例子:
Wordthatcanbehyphenated wordthatcanbehyphenated
\index{entry}\nolinebreak\hspace{0pt}longwordwithindexthatmustbehyphenated
wordthatcanbehyphenated