[Tex/LaTex] How to set the space between two index entries with the same character

indexingline-spacingspacing

When I make an index, I get only between the different characters (b,s,t) an optimal vertical spacing.

\usepackage{makeidx}\makeindex
\index{book}
\index{summer!sun}
\index{summer!heat}
\index{sound}
\index{tower}

Because I've only a few index entries, the vertical spacing between summer and sound (starting with the same character) should be the same as for different letters like (book and summer or sound and tower: one blank line of 1em).

I've tried to find for a solution in the internet and in the package documentation but was not successful.

Is this somehow possible with makeidx?

Best Answer

You can redefine \@idxitem to have a vertical space preceding it, while \indexspace does nothing. Also \subitem needs to be redefined, otherwise it would add the vertical space as well.

For separating the first entry from the heading, a \vspace{12pt} instruction is added to \theindex, modify it to suit.

% arara: pdflatex
% arara: makeindex
% arara: pdflatex

\documentclass{article}
\usepackage{etoolbox}
\usepackage{makeidx}\makeindex

\makeatletter
\def\@idxitem{\par\addvspace{10\p@ \@plus 5\p@ \@minus 3\p@}\hangindent 40\p@}
\def\subitem{\par\hangindent 40\p@ \hspace*{20\p@}}
\def\subsubitem{\par\hangindent 40\p@ \hspace*{30\p@}}
\def\indexspace{}
\patchcmd\theindex{\indexname}{\indexname\vspace{12pt}}{}{}
\makeatother

\begin{document}
x
\index{book}
\index{summer!sun}
\index{summer!heat}
\index{summer!heat!sweat}
\index{sound}
\index{tower}

\count255=0
\loop\ifnum\count255<40
\advance\count255 1
\expandafter\index\expandafter{\romannumeral\count255}
\repeat

\printindex
\end{document}

The arara directives are what I used to ease compilation; the \loop just fills in some more index entries so we arrive at the second column.

enter image description here

If I change the code above into

\makeatletter
\def\@idxitem{\par\addvspace{5\p@ \@plus 2.5\p@ \@minus 1.5\p@}\hangindent 40\p@}
\def\subitem{\par\hangindent 40\p@ \hspace*{20\p@}}
\def\subsubitem{\par\hangindent 40\p@ \hspace*{30\p@}}
\renewcommand\indexspace{\par\addvspace{10\p@ \@plus 5\p@ \@minus 3\p@}}
\patchcmd\theindex{\indexname}{\indexname\vspace{12pt}}{}{}
\makeatother

then the space between different letters will be double of the space between entries starting with the same letter.

enter image description here

Related Question