5

The following is the type of code I made.

\documentclass{article}
\usepackage{makeidx}
\makeindex
\begin{document}

... something\index{Lois!Lane} ...

\printindex
\end{document}

I'd like an index with a dash before any subentry (obviously, under the respectively entry)

Marco, Ill, 1
Lois,
 -  Lane, 1 
 -  John, 1

How can I do anything like this? What if a want with a comma after every dash? Like this

Marco, Ill, 1
Lois,
 -  , Lane, 1 
 -  , John, 1

EDIT

If it is not possible to perfectly allign the dash with makeidx, what about Xindy?

1 Answer 1

7

This requires the makeindex style file to be changed/extended.

For example, a dashindex.ist can be defined to be

item_1  "\n \\subitem -- , "
item_x1 "\n \\subitem -- , "

saying, that the sub levels should be preceeded by a dash and a comma.

Calling flow:

pdflatex foo

makeindex -s dashindex.ist foo

pdflatex foo

\documentclass{article}
\usepackage{xcolor}
\usepackage{makeidx}
\makeindex
\begin{document}

... somethex\index{Lois!Lane} ...

\index{Gandalf!The Grey}
\index{Gandalf!Stormcrow}
\index{Gandalf!Mithrandir}%
\index{Lois!John}
\index{Lois!Clark}

\printindex


\end{document}

enter image description here

A direct manipulation of \subitem

This cures the indentation problem -- in this case, no special .ist file is needed. I've set the subitem indent to 5pt, but this could be changed to basically any length value.

\documentclass{article}
\usepackage{makeidx}
\newlength{\subitemindent}
\setlength{\subitemindent}{5pt}
\makeindex
\makeatletter
\renewcommand{\subitem}{\par\hangindent 40\p@ \hspace*{\subitemindent} -- , }
\makeatother
\begin{document}

... somethex\index{Lois!Lane} ...

\index{Gandalf!The Grey}
\index{Gandalf!Stormcrow}
\index{Gandalf!Mithrandir}%
\index{Lois!John}
\index{Lois!Clark}

\printindex

\end{document}

enter image description here

10
  • Is it not possible to have the dash exactly (namely centered) under the first entry?
    – W4cc0
    Commented Nov 8, 2014 at 14:33
  • @W4cc0: I don't know, I'll have look later on, ok?
    – user31729
    Commented Nov 8, 2014 at 14:40
  • Yes, do not worry. I was just asking because with short words it happens that the dash is under the numbers and that is awful.
    – W4cc0
    Commented Nov 8, 2014 at 14:41
  • @W4cc0: It could be possible using xindy instead of makeindex...
    – user31729
    Commented Nov 8, 2014 at 14:42
  • 1
    @W4cc0: Well, it might be possible anyway, but at the moment I am not sure how to align those entries. Although you already accepted it, I will try to improve my solution
    – user31729
    Commented Nov 8, 2014 at 16:22

You must log in to answer this question.

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