1

When the "word" in \index{WORD} is longer than columnwidth, one can use \hyphenation{} or local rule \- to have the part of word in several lines.

However this approach gives the unexpected new line before the page number.

Can anybody help me to remove this new line command when I use hyphenation?

The way of problem solving can be discussed only with imakeidx because of ist files that I need to use.

MWE (adopted from this example).

    \documentclass{memoir}
    \usepackage{imakeidx}
    \usepackage{blindtext}
    \makeindex[program=makeindex,
    title={First},
    name=first]

    %global does not work %use local hyphenation instead
    %\hyphenation{foofoofoo-foofoofoo-foofoofoo-foofoofoofoofo-ofoofoofoo-foo}
    %\hyphenation{barbarbarbarbar-barbarbarbarbarb-arbarbarbarba-rbarbarbar}
    \begin{document}
    Einstein\index[first]{Einstein! NewLine\-NewLine\-NewLine\-NewLine\-NewLine\-}
    Heisenberg\index[first]{Heisenberg} 
    \blindtext[4]
    \blindtext[4]
    Einstein\index[first]{Einstein! NewLine\-NewLine\-NewLine\-NewLine\-NewLine\-}
    \index[first]{foofoofoofoo\-foofoofoofoofoofoo\-foofoofoofoofoo\-foofoofoo}
    \index[first]{barbarbar\-barbarbarbar\-barbarbarbarbarbar\-barbarbarbarbar}
    \blindtext
    %there is also undesirable blank page after this Index
    \printindex[first] 
    \end{document}

PDF

enter image description here

Useful link about MakeIndex commands. All my attempts to use settings commands from this instructions failed.

2 Answers2

2

Create a file name first.mst ("first" as this the name of your index) with the following content

delim_0 ",~"
delim_1 ",~"
delim_n ",~"

When you then compile your example, makeindex will insert unbreakable spaces between the page numbers and this will avoid the line and page breaks:

enter image description here

Ulrike Fischer
  • 327,261
1

You are using memoir class for your document. So, by default, you have a recto-verso layout for your pages. Not to do so, you can use oneside option in your document definition. This will remove the blank pages.

Another problem in your MWE is how you define the indices in Latex. Make sure you define each index once. My suggestion, if you are interested in long indices, is to use a one column index.

Here is my code for your problem:

\documentclass[oneside]{memoir}
\usepackage{imakeidx}
\usepackage[columns=1]{idxlayout}
\usepackage{blindtext}
\makeindex[program=makeindex,
title={First},
name=first]

\begin{document}
This is Vladimir's example text to try indexing in \LaTeX. He would like to index Einstein\index[first]{Einstein}, Heisenberg\index[first]{Heisenberg}, foo\index[first]{foofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoo} and bar \index[first]{barbarbarbarbarbarbarbarbarbarbarbarbarbarbar}.
\printindex[first] 
\end{document}

which produces a 2-page documents having the following as the index:

enter image description here

  • thank you for the answer. I forgot about oneside option. Unfortunately, I have to use two-column, so we need to solve the problem. The simplest way, that I use in \index{}, is just to put spaces between letters in the word. For example, bar bar instead of \hyphenation{bar-bar}. – Vladimir Parkhomenko Sep 20 '17 at 14:29