2

I am trying to right align the pagenumbers in my index. I use imakeidx and tried to use a custome index style file (.ist). I would like to keep the two column layout of imakeidx. I tried using \hfill as delimiter however this seems to yield always the same width of gap.

How do I rightalign the page numbers while keeping the two column layout?

index.ist-file:

delim_0 "\\hfil"
delim_1 "\\hfil"
delim_2 "\\hfil"

mwe:

\documentclass{report}
\usepackage{imakeidx}
\makeindex[options=-s ./index]
\begin{document}
Indexing\index{what!index} some\index{some} demonstrative\index{demonstrative} entires.

\printindex
\end{document}

enter image description here

3
  • 1
    Use \hfill and not \hfil
    – egreg
    Sep 9, 2013 at 19:40
  • To expand on egreg's comment, paraphrasing Knuth (p.71) "you can think of it as if \hfil has one mile of stretchability, while \hfill has a trillion miles." If an \hfill exists in the underlying code, it will prevent your \hfils from stretching. That is why you have to fight \hfills with \hfills. Sep 9, 2013 at 19:52
  • 1
    if there are just one or two page numbers per index entry, then \hfill should do the job. but if there are lots of numbers for an entry, such that more than one line is required, then extra measures will have to be taken. see the texbook, appendix d, pp.392-394 for a rather extreme case (the math. reviews "key index"). it would look even nicer with hanging punctuation, but it was quite enough of a problem in 1980 to get this to work reliably; this was one of the problems i took with me to stanford when i went there to learn tex. Sep 9, 2013 at 20:33

1 Answer 1

2

The command \hfil is not working.

Please try this ist file:

delim_0 "\\dotfill"
delim_1 "\\hfill"
delim_2 "\\hfill" 

\dotfill (for better reading fills the line with dots, \hfill has no dots, but the numer is right justified.

Result:

enter image description here

2
  • 1
    How to right align the page numbers when I have multiple lines of page numbers?
    – bmv
    Nov 22, 2020 at 13:12
  • @bmv – depending precisely what you want, you may find that \usepackage{imakeidx} \usepackage{etoolbox} \patchcmd\theindex{\raggedright}{\raggedleft}{}{} does this.
    – richard
    Aug 4, 2022 at 22:06

You must log in to answer this question.

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