考虑一下代码
\documentclass{book}
\usepackage{imakeidx}
\let\cleardoublepage\clearpage
\makeindex
%\usepackage[font=small]{idxlayout}
\usepackage{idxlayout}
\usepackage{xcolor}
\begin{document}
\LARGE
Some words.\index{\textbf{HEADING1}! \textbf{\color{red}{Subheading}}! The entry immediately above HEADING2.}
Some words.\index{\textbf{HEADING2}! \textbf{\color{red}{Subheading}}! I would like to be able to globally specify the size of the gap between a new heading (such as HEADING2 and the last line of the entry immediately above it.}
\idxlayout{columns=1}
\printindex
\end{document}
生成索引
观察 HEADING2 之前的垂直空间有多小。
问题:如何增加 HEADING1 索引条目最后一行与 HEADING2 显示位置之间的间距?我希望能够为所有后续标题指定此间隙的值。
谢谢。
答案1
我在下面实现了其他一些可能对您的设置有用的功能 - 一种设置条目和的键值方法\index
。heading
这subheading
消除了最终用户的格式规范,使您在使用标题/子标题时更加一致/统一。也就是说,您不必\textbf{<heading>}
每次都指定标题。相反,
\myindex[heading={<heading>},subheading={<subheading>}]{<index entry>}
将检查您是否提供了heading
/subheading
并<index entry>
相应地进行索引。
此外,\addvspace{<len>}
每个都添加,heading
以确保有足够的间隙<len>
多于(heading
除了第一的标题应该位于指数标题;可以更改)。
\documentclass{article}
\usepackage{imakeidx}
\makeindex
\usepackage{idxlayout}
\usepackage{xcolor}
\usepackage{xkeyval}
\makeatletter
\DeclareDocumentCommand{\insertidxheadinggap}{}{%
% Delayed execution of macro (https://tex.stackexchange.com/a/89187/5764)
\def\insertidxheadinggap{\addvspace{\baselineskip}}}% Add \baselineskip above headings (excluding first)
\define@cmdkey{idx}{heading}[\relax]{}% Heading title
\define@cmdkey{idx}{subheading}[\relax]{}% Subheading title
\newcommand{\myindex}[2][]{%
\setkeys{idx}{%
heading,subheading,% Default settings
#1}% User-provided settings
% Construct \index{...} command based on heading/subheading supplied by user
\begingroup\edef\x{\endgroup
\noexpand\index{%
\expandafter\ifx\cmdKV@idx@heading\relax\else
\cmdKV@idx@heading @%
\insertidxheadinggap%
\noexpand\textbf{\cmdKV@idx@heading}!% Heading format: \textbf{<heading>}
\fi
\expandafter\ifx\cmdKV@idx@subheading\relax\else
\noexpand\textbf{\noexpand\color{red}\cmdKV@idx@subheading}!% Subheading format: \textbf{\color{red}<subheading}
\fi
#2% Index entry
}}\x
}
\makeatother
\begin{document}
Some words.%
\myindex[heading={Heading 1},subheading=Subheading]{The entry immediately above ``Heading 2.''}
Some words.%
\myindex[heading={Heading 2},subheading=Subheading]{I would like to be able to globally specify the size
of the gap between a new heading (such as ``Heading 2'' and the last line of the entry immediately above it).}
\myindex[heading={Heading 2},subheading={Another subheading}]{Something}
\myindex[heading={Heading 2}]{Somethine else}
\myindex[heading={Heading 2},subheading=Subheading]{Another entry}
\myindex[heading={Heading 321}]{Some other index entry}
\idxlayout{columns=1}
\printindex
\end{document}
上述方法假设您将拥有大量标题,而没有非标题条目,因为它们可能没有适当的间距调整。此外,可以扩展此方法以包含标题的“排序字符串”,这将允许您操纵标题在其他标题中的位置。