5

I have troubles dealing with widows in an index. Imagine an index created of senders and receivers of letters. \item is the receiver \subitem is the sender and \subsubitem is the day the letter was sent. How can I renew the commands so that \item would be the best place for a pagebreak, \subitem is okay only if there is at least one subsubitem following and there should be no pagebreak before subsubitems?

MWE

\documentclass[a5paper]{scrbook}
\usepackage[english]{babel}
\usepackage{makeidx}\makeindex
\widowpenalty=10000         % avoid widows
\clubpenalty=10000          % avoid orphans
\raggedbottom
\begin{document}
text
\index{Adam, Ant!letters from Bernie Bert!1.1.1900}
\index{Adam, Ant!letters from Bernie Bert!2.1.1900}
\index{Adam, Ant!letters from Bernie Bert!3.1.1900}
\index{Adam, Ant!letters from Bernie Bert!4.1.1900}
\index{Adam, Ant!letters from Bernie Bert!5.1.1900}
\index{Adam, Ant!letters from Bernie Bert!6.1.1900}
\index{Adam, Ant!letters from Bernie Bert!7.1.1900}
\index{Adam, Ant!letters from Bernie Bert!8.1.1900}
\index{Adam, Ant!letters from Bernie Bert!9.1.1900}
\index{Adam, Ant!letters from Bernie Bert!2.2.1900}
\index{Adam, Ant!letters from Bernie Bert!2.2.1900}
\index{Adam, Ant!letters from Bernie Bert!3.2.1900}
\index{Adam, Ant!letters from Bernie Bert!4.2.1900}
\index{Adam, Ant!letters from Bernie Bert!5.2.1900}
\index{Adam, Ant!letters from Bernie Bert!6.2.1900}
\index{Adam, Ant!letters from Bernie Bert!7.2.1900}
\index{Adam, Ant!letters from Bernie Bert!8.2.1900}
\index{Adam, Ant!letters from Bernie Bert!9.2.1900}
\index{Adam, Ant!letters from Bernie Bert!10.2.1900}
\index{Adam, Ant!letters from Bernie Bert!11.2.1900}
\index{Adam, Ant!letters from Bernie Bert!12.2.1900}
\index{Adam, Ant!letters from Bernie Bert!13.2.1900}
\index{Bert, Bernie!letters from Caius Caligula!1.1.1900}
\index{Bert, Bernie!letters from Caius Caligula!2.1.1900}
\index{Bert, Bernie!letters from Caius Caligula!3.1.1900}
\index{Bert, Bernie!letters from Caius Caligula!4.1.1900}
\index{Bert, Bernie!letters from Caius Caligula!5.1.1900}
\index{Bert, Bernie!letters from Caius Caligula!6.1.1900}
\index{Bert, Bernie!letters from Caius Caligula!7.1.1900}
\index{Bert, Bernie!letters from Caius Caligula!8.1.1900}
\index{Bert, Bernie!letters from Caius Caligula!9.1.1900}
\index{Bert, Bernie!letters from Caius Caligula!2.2.1900}
\index{Bert, Bernie!letters from Caius Caligula!2.2.1900}
\index{Bert, Bernie!letters from Caius Caligula!3.2.1900}
\index{Bert, Bernie!letters from Caius Caligula!4.2.1900}
\index{Bert, Bernie!letters from Caius Caligula!5.2.1900}
\index{Bert, Bernie!letters from Caius Caligula!6.2.1900}
\index{Bert, Bernie!letters from Caius Caligula!7.2.1900}
\index{Bert, Bernie!letters from Caius Caligula!8.2.1900}
\index{Bert, Bernie!letters from Caius Caligula!9.2.1900}
\index{Bert, Bernie!letters from Adam Ant!1.1.1900}
\index{Bert, Bernie!letters from Adam Ant!2.1.1900}
\index{Bert, Bernie!letters from Adam Ant!3.1.1900}
\index{Bert, Bernie!letters from Adam Ant!4.1.1900}
\index{Bert, Bernie!letters from Adam Ant!5.1.1900}
\index{Bert, Bernie!letters from Adam Ant!6.1.1900}
\index{Bert, Bernie!letters from Adam Ant!7.1.1900}
\index{Bert, Bernie!letters from Adam Ant!8.1.1900}
\index{Bert, Bernie!letters from Adam Ant!9.1.1900}
\index{Bert, Bernie!letters from Adam Ant!2.2.1900}
\index{Bert, Bernie!letters from Adam Ant!2.2.1900}
\index{Bert, Bernie!letters from Adam Ant!3.2.1900}
\index{Bert, Bernie!letters from Adam Ant!4.2.1900}
\index{Bert, Bernie!letters from Adam Ant!5.2.1900}
\index{Bert, Bernie!letters from Adam Ant!6.2.1900}
\index{Bert, Bernie!letters from Adam Ant!7.2.1900}
\index{Bert, Bernie!letters from Adam Ant!8.2.1900}
\index{Bert, Bernie!letters from Adam Ant!9.2.1900}

\printindex

\end{document} 

This should not happen at the pagebreak: enter image description here

2
  • i can suggest a manual fix, that requires input of a pseudo-entry, but this is useful only after the index is otherwise final. would this be or interest? Commented Dec 14, 2017 at 21:57
  • hmm. I'd prefer a real fix but of course: any help is appreciated! Commented Dec 14, 2017 at 22:01

2 Answers 2

2

If you redefine \subitem and \subsubitem not to end a paragraph, the \widowpenalty and \clubpenalty can do their job:

\renewcommand\subitem{\unskip\nobreak\hfill\break\hspace*{-30pt}}
\renewcommand\subsubitem{\unskip\nobreak\hfill\break\hspace*{-20pt}}

enter image description here

The negative spaces are used in order to countermand the \hangindent 40pt issued by \item (actually \@idxitem).

2

this is not an ideal solution, but it does allow one to manually specify a column/page break in an index. of course, this should be applied only after everything else is otherwise final.

determine the location of the desired break, and construct a sort string that will fall between the last item to appear on the "first" page and the item to be moved to the next page. in the example provided, this string will suffice:

Bert, Bernie!letters from BBB

the example (a copy of the one in the question, aside from additions) should otherwise be self-explanatory.

\documentclass[a5paper]{scrbook}
\usepackage[english]{babel}
\usepackage{makeidx}\makeindex
\widowpenalty=10000         % avoid widows
\clubpenalty=10000          % avoid orphans
\raggedbottom

%%% provide a mechanism for inserting a dummy index entry in the main source
%%% file to break an index column at the bottom of a column when a lone
%%% higher-level entry is separated from secondary entries in the next column.
%%% first, a command to "disappear" the page number.
\newcommand{\idxnopage}[1]{{}}
%%% a command to gobble the comma before the page number
\providecommand{\gobble}[1]{{}}
%%% the user command to insert the break
\makeatletter
\newcommand{\moveindexentry}[1]{%
  \index{#1@\string\pagebreak\string\gobble \string|idxnopage}}
\makeatother 
%%% end of commands to break column

\begin{document}
text
\index{Adam, Ant!letters from Bernie Bert!1.1.1900}
\index{Adam, Ant!letters from Bernie Bert!2.1.1900}
\index{Adam, Ant!letters from Bernie Bert!3.1.1900}
\index{Adam, Ant!letters from Bernie Bert!4.1.1900}
\index{Adam, Ant!letters from Bernie Bert!5.1.1900}
\index{Adam, Ant!letters from Bernie Bert!6.1.1900}
\index{Adam, Ant!letters from Bernie Bert!7.1.1900}
\index{Adam, Ant!letters from Bernie Bert!8.1.1900}
\index{Adam, Ant!letters from Bernie Bert!9.1.1900}
\index{Adam, Ant!letters from Bernie Bert!2.2.1900}
\index{Adam, Ant!letters from Bernie Bert!2.2.1900}
\index{Adam, Ant!letters from Bernie Bert!3.2.1900}
\index{Adam, Ant!letters from Bernie Bert!4.2.1900}
\index{Adam, Ant!letters from Bernie Bert!5.2.1900}
\index{Adam, Ant!letters from Bernie Bert!6.2.1900}
\index{Adam, Ant!letters from Bernie Bert!7.2.1900}
\index{Adam, Ant!letters from Bernie Bert!8.2.1900}
\index{Adam, Ant!letters from Bernie Bert!9.2.1900}
\index{Adam, Ant!letters from Bernie Bert!10.2.1900}
\index{Adam, Ant!letters from Bernie Bert!11.2.1900}
\index{Adam, Ant!letters from Bernie Bert!12.2.1900}
\index{Adam, Ant!letters from Bernie Bert!13.2.1900}
\moveindexentry{Bert, Bernie!letters from BBB}
\index{Bert, Bernie!letters from Caius Caligula!1.1.1900}
\index{Bert, Bernie!letters from Caius Caligula!2.1.1900}
\index{Bert, Bernie!letters from Caius Caligula!3.1.1900}
\index{Bert, Bernie!letters from Caius Caligula!4.1.1900}
\index{Bert, Bernie!letters from Caius Caligula!5.1.1900}
\index{Bert, Bernie!letters from Caius Caligula!6.1.1900}
\index{Bert, Bernie!letters from Caius Caligula!7.1.1900}
\index{Bert, Bernie!letters from Caius Caligula!8.1.1900}
\index{Bert, Bernie!letters from Caius Caligula!9.1.1900}
\index{Bert, Bernie!letters from Caius Caligula!2.2.1900}
\index{Bert, Bernie!letters from Caius Caligula!2.2.1900}
\index{Bert, Bernie!letters from Caius Caligula!3.2.1900}
\index{Bert, Bernie!letters from Caius Caligula!4.2.1900}
\index{Bert, Bernie!letters from Caius Caligula!5.2.1900}
\index{Bert, Bernie!letters from Caius Caligula!6.2.1900}
\index{Bert, Bernie!letters from Caius Caligula!7.2.1900}
\index{Bert, Bernie!letters from Caius Caligula!8.2.1900}
\index{Bert, Bernie!letters from Caius Caligula!9.2.1900}
\index{Bert, Bernie!letters from Adam Ant!1.1.1900}
\index{Bert, Bernie!letters from Adam Ant!2.1.1900}
\index{Bert, Bernie!letters from Adam Ant!3.1.1900}
\index{Bert, Bernie!letters from Adam Ant!4.1.1900}
\index{Bert, Bernie!letters from Adam Ant!5.1.1900}
\index{Bert, Bernie!letters from Adam Ant!6.1.1900}
\index{Bert, Bernie!letters from Adam Ant!7.1.1900}
\index{Bert, Bernie!letters from Adam Ant!8.1.1900}
\index{Bert, Bernie!letters from Adam Ant!9.1.1900}
\index{Bert, Bernie!letters from Adam Ant!2.2.1900}
\index{Bert, Bernie!letters from Adam Ant!2.2.1900}
\index{Bert, Bernie!letters from Adam Ant!3.2.1900}
\index{Bert, Bernie!letters from Adam Ant!4.2.1900}
\index{Bert, Bernie!letters from Adam Ant!5.2.1900}
\index{Bert, Bernie!letters from Adam Ant!6.2.1900}
\index{Bert, Bernie!letters from Adam Ant!7.2.1900}
\index{Bert, Bernie!letters from Adam Ant!8.2.1900}
\index{Bert, Bernie!letters from Adam Ant!9.2.1900}

\printindex

\end{document}

dummy entries like the one in the example can be placed anywhere in the source file. it is probably a good idea to keep them all in one place so that they can be found easily in case changes are needed.

You must log in to answer this question.

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