11

I've got a index generated with makeindex but when compiling the file again, when the index is generated, I get a bunch of overfull \hbox.

This is an example of an index that results in overfull:

\begin{theindex}
  \item Type, 149, 155
    \subitem GetProperties(), 127, 130, 135, 150
\end{theindex}

I don't want to change the .ind-file manually, I'm guessing that is the wrong approach; so what should I do here?

I think that adding a \newline before 127 above would work, but as I said, I don't want to change this file directy.

Edit - Reproducing the error

Here is a sample to re-produce the error that I am getting, first you need the page "CreateSpace".

Then I am using this code to generate the file:

\documentclass{book}
\usepackage[size=novel,trim=0,paper=white,preview=false,gutter=0.5in,inner=0.25in,outer=0.25in,top=0.75in,bottom=0.75in,geometryextra={twoside,heightrounded,truedimen},colourpackage=xcolor,colorpackage=xcolor]{createspace}

\usepackage{index}
\usepackage{lipsum}
\usepackage{courier}

\makeatother
\makeindex
\begin{document}

\index{A}
\index{B}
\index{C}
\index{D}
\index{E}
\index{F}
\index{G}
\index{H}
\index{I}
\index{J}
\index{K}
\index{L}
\index{M}
\index{N}
\index{O}
\index{P}
\index{T}
\index{U}
\index{V}
\index{X}
\index{Y}
\index{A1}
\index{B2}
\index{C3}
\index{D4}
\index{E5}
\index{F6}
\index{G7}
\index{H8}
\index{I9}
\index{J10}
\index{K11}
\index{L12}
\index{M13}
\index{N14}
\index{O15}
\index{P16}
\index{T20}
\index{U21}
\index{V22}
\index{X23}
\index{Y24}

\lipsum[1-50]
\lipsum[1-50]
\lipsum[1-50]
\lipsum[1-50]
\lipsum[1-50]
\lipsum[1-50]
\lipsum[1-50]
\lipsum[1-50]
\lipsum[1-50]
\lipsum[1-50]
\lipsum[1-50]
\lipsum[1-50]
\index{Type!GetProperties()}
\lipsum[1-50]
\lipsum[1-50]
\lipsum[1-50]
\lipsum[1-50]
\lipsum[1-50]
\lipsum[1-50]
\lipsum[1-50]
\lipsum[1-50]
\lipsum[1-50]
\lipsum[1-50]
\index{Type!GetProperties()}
\lipsum[1-50]
\lipsum[1-50]
\lipsum[1-50]
\lipsum[1-50]
\lipsum[1-50]
\index{Type!GetProperties()}
\lipsum[1-50]
\lipsum[1-50]
\lipsum[1-50]
\lipsum[1-50]
\lipsum[1-50]
\index{Type!GetProperties()}
\lipsum[1-50]
\lipsum[1-50]
\lipsum[1-50]
\index{Type!GetProperties()}
\lipsum[1-50]
\lipsum[1-50]
\lipsum[1-50]
\index{Type}
\index{Type!GetProperties()}

\printindex

\end{document}

After that I run: makeindex -s headings.ist MWE.idx

headings.ist contains the following:

headings_flag 1
heading_prefix "\\textbf\{\\large "
heading_suffix "\}"

If you now go to the end of the generated PDF, you will see that the index is out of the page margins:

enter image description here

5
  • Would you please try and get a MWE so that we can play with it?
    – egreg
    Jul 12, 2012 at 14:12
  • @egreg, That's the only code that I got. Don't know how to put together a MWE on this. Jul 12, 2012 at 14:28
  • Write a document with a couple of \index commands. What's needed are the class, the pagination parameters and the way you set the index.
    – egreg
    Jul 12, 2012 at 14:30
  • @egreg, It's not really that simple, the "MWE" will be quite big. Because the indexes most likely need to be in the right hand column to reproduce the error. Jul 12, 2012 at 14:42
  • @egreg, Updated with instructions on how to reproduce this. I just want to note also, that by manually editing the ind-file and adding \newline, the error goes away, but it feels like I'm doing something wrong when I need to manualy edit an auto-generated file like that. Jul 12, 2012 at 14:56

2 Answers 2

8

You can first try relaxing the space parameters in the index:

\usepackage{etoolbox}
\appto{\theindex}{\spaceskip=.33333em plus .33333em minus .11111em }

This will allow the interword space to stretch a bit more (the usual stretching value is .22222em).

A different strategy might be

\usepackage{etoolbox}
\appto{\theindex}{\emergencystretch=6em }

which should result in a similar result.

The more drastic

\usepackage{etoolbox}
\appto{\theindex}{\sloppy}

is definitely not recommended.

5
  • I'm using the exact code in the MWE, but I added the two lines that you mentioned. It's printed on the first page. See my code here to verify: privatepaste.com/8f584a2b96/latex and here is a screenshot of that page dl.dropbox.com/u/62721809/MWE_pdf.png Jul 12, 2012 at 17:37
  • it seems like it works on the lipsum MWE, but not when I moved it to the real book. Maybe I need to experiment with the numbers a bit. Jul 12, 2012 at 17:56
  • Thanks by the way. Also, is this really recommended too do? Jul 12, 2012 at 17:56
  • @FilipEkberg Yes, of course; the index doesn't need so strict bounds on paragraphs as regular text. The ragged right typesetting suggested by Kurt should be considered too.
    – egreg
    Jul 12, 2012 at 18:01
  • Awesome! I still consider myself a LaTeX newbie, writing my first book with it. :) Thanks for all the help, I'll wait a couple of days before accepting an answer, want to see if Kurt adds a MWE that I can compare with. Thanks! Jul 12, 2012 at 19:04
7

An Index needs no justification. With the package ragged2e you can use the macro \RaggedRight to get a left-justified index. The ancillary effect of this: no overfull \hbox.

For example:

\documentclass[%
  a5paper      % papersize
 ,draft        % to show the overfull hbox
]{article}

\usepackage{index,lipsum,lmodern}
\usepackage{ragged2e}   % ragged margin with hyphenation
\makeindex

\begin{document}
\lipsum[1]\index{Type!GetProperties()}\clearpage\lipsum[1]\clearpage
\lipsum[1]\index{Type!GetProperties()}\clearpage\lipsum[1]\clearpage
\lipsum[1]\index{Type!GetProperties()}\clearpage\lipsum[1]\clearpage
\lipsum[1]\index{Type!GetProperties()}\clearpage\lipsum[1]\clearpage
\lipsum[1]\index{Type!GetProperties()}\clearpage\lipsum[1]\clearpage
\lipsum[1]\index{Type!GetProperties()}\clearpage\lipsum[1]\clearpage
\lipsum[1]\index{Type!GetProperties()}\clearpage
\index{Type}\index{Test}\index{Type!GetProperties()}

{              % start group
%\RaggedRight  % left-justified setting    % line 21
\printindex    % insert index here
}              % end group
\end{document}

You will get the warning "overfull hbox". With the class option draft the overfull box is marked with an black box. Delete the leading comment in line 21 and the warning disappears ...

My used index file is:

\begin{theindex}
{\bfseries\hfil T\hfil}\nopagebreak

  \item Test, 14
  \item Type, 14
    \subitem GetProperties(), 1, 3, 5, 7, 9, 11, 13, 14

\end{theindex}

My used ist file is:

% Index-Stildatei 
headings_flag    1  % Big letter before group
heading_prefix   "{\\bfseries\\hfil "
heading_suffix   "\\hfil}\\nopagebreak\n"
symhead_positive "Symbole"

delim_0  
delim_1  
delim_2 
0

You must log in to answer this question.

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