1

Consider the MWE

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

\newcommand{\beforeheadspace}{.7ex}% <<<<<<<<<<<<<<<<<
\newcommand{\beforesubheadspace}{.4ex}% <<<<<<<<<<<<<<<<<

\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{HEADING@\textbf{HEADING}!1@ \textbf{\color{red}{Subheading}}! This sentence is the first entry.}
\index{HEADING@\textbf{HEADING}!2@ \textbf{\color{red}{Subheading}}! This sentence of anoher set of words -- illustrates the effect.}
\index{HEADING@\textbf{HEADING}!3@ \textbf{\color{red}{Subheading}}! These words comprise the third entry.}
               
\idxlayout{columns=1}
\printindex
\end{document}

which produces the Index:

enter image description here

In the code, I have added some additional vertical space between the subheadings and entries as follows:

\newcommand{\beforeheadspace}{.7ex}% <<<<<<<<<<<<<<<<<
\newcommand{\beforesubheadspace}{.4ex}% <<<<<<<<<<<<<<<<<

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

But, this seems to be causing the problem, for when I remove these lines and run the code, the undesirable blank line disappears.

QUESTION: How may I add the aforesaid additional vertical space between the subheadings and entries, while avoiding the occasional blank line from appearing when an entry extends too far to the right.

Remark: I do not ever recall encountering the blank line problem when I do not include the newcommand and renewcommand code---such index entries either stay on one line or break onto the next with at least the page number displayed.

Thank you.

1 Answer 1

1

What you observe is some blank stuff at the end of the long line that wraps to the next line (resulting in an apparently empty line), before \par starts a new paragraph.

You can either switch \vspace* and \par:

\renewcommand\subitem{\par\vspace*{\beforeheadspace}\hangindent 40pt \hspace*{20pt}}

Or you can remove the optional trailing stuff yourself by \unskip:

\renewcommand\subitem{\unskip\vspace*{\beforeheadspace}\par\hangindent 40pt \hspace*{20pt}}
2
  • (I think an extra closing brace is needed in the first renewcomand.) Both suggestions work nicely. Many thanks.
    – DDS
    Commented Jan 1, 2022 at 15:17
  • @mlchristians Thanks for the note, I corrected the typo
    – gernot
    Commented Jan 1, 2022 at 21:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .