I have managed to create an index where the page number links to the correct page. But I would like it to link to the correct part of the page, not to the top of the page. Is this possible?
Here is the code I have so far (on GitHub with Makefile) and explicitly:
\documentclass[a5paper]{book}
\usepackage{makeidx} % for automatically generation of an index
\usepackage{hyperref} % has to be after makeidx
\usepackage[margin=2.5cm]{geometry} % layout
\makeindex
\begin{document}
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam
nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam
erat,
sed diam voluptua. At vero eos et accusam et justo duo dolores et ea
rebum. Stet \index{clita} clita kasd gubergren, no sea takimata sanctus
est Lorem
ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur
sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore
et dolore magna aliquyam erat, sed diam voluptua. At vero eos et
accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren,
no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum
dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam
voluptua. At vero eos et accusam et justo duo dolores et ea rebum.
Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum
dolor sit amet.
Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse
molestie consequat, vel illum dolore eu feugiat nulla facilisis at
vero eros et accumsan et iusto odio dignissim qui blandit praesent
luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam
nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat
volutpat.
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam
nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam
erat,
sed diam voluptua. At vero eos et accusam et justo duo dolores et ea
rebum. Stet clita kasd gubergren, no sea takimata sanctus
est Lorem
ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur
sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore
et dolore magna aliquyam erat, sed diam voluptua. At vero eos et
accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren,
no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum
dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam
voluptua. At vero eos et accusam et justo duo dolores et ea rebum.
Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum
dolor sit amet.
Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse
molestie consequat, vel illum \index{dolore} dolore eu feugiat nulla facilisis at
vero eros et accumsan et iusto odio dignissim qui blandit praesent
luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam
nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat
volutpat.
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam
nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam
erat,
sed diam voluptua. At vero eos et accusam et justo duo dolores et ea
rebum. Stet \index{clita} clita kasd gubergren, no sea takimata sanctus
est Lorem
ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur
sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore
et dolore magna aliquyam erat, sed diam voluptua. At vero eos et
accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren,
no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum
dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam
voluptua. At vero eos et accusam et justo duo dolores et ea rebum.
Stet clita \index{kasd} kasd gubergren, no sea takimata sanctus est Lorem ipsum
dolor sit amet.
Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse
molestie consequat, vel illum dolore eu feugiat nulla facilisis at
vero eros et accumsan et iusto odio dignissim qui blandit praesent
luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam
nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat
volutpat.
\printindex % print the automatically created index
\end{document}
Adobe Reader 9and UbuntusDocument Viewer 2.30.3. It worked, but the view was one line too low. Is it possible to fix that? (I've also tried it withGoogle Chrome, but it didn't work at all. I guess this is an error of Chrome and can't be fixed.) – Martin Thoma Oct 17 '12 at 06:23amsmathpackage. If you try to index a sum like this:\xindex{$\sum_{i\in I}\kappa_i$}some spurious '@' appear in the idx file, and the entry gets rejected. On the other hand, this works with\lim. Do you have any idea on how to solve this? – Pedro Sánchez Terraf Jan 08 '17 at 18:11.idxfile. If so, try adding\protectbefore the command to prevent expansion. If that doesn't work, I think you'll need to post a follow-up question with a MWE that shows the problem. – Nicola Talbot Jan 09 '17 at 13:18\usepackage{amsmath}before the\newcounter, and add\xindex{$\sum_{i\in I}\kappa_i$}anywhere in the text. In the idx file, I obtain an entry of the shape:\indexentry{$\DOTSB \sum@ \slimits@ _{i\in I}\kappa _i$|indexanchor{index-1}}{1},which is rejected while running
– Pedro Sánchez Terraf Jan 09 '17 at 14:24makeindex. Protecting\sumsolves the problem, but perhaps you can come up with a uniform solution. If that's so, I'll be happy to post a new question for you.amsmathchanges the definition of\sumwhich is causing the expansion. I can't think of a uniform solution (there may be commands that need expansion in some contexts) but it's possible someone else might be able to suggest something. (Another possibility is to make the problem commands robust, e.g. usingetoolbox's\robustifycommand, but you still need to know which commands are problematic.) – Nicola Talbot Jan 10 '17 at 09:19\xindexmacro are a bit taller (it can be seen in your example code). A solution is that the hypertarget have height 0.\raiseboxhas an optional argument, but it can't be used inside that code. I managed to define a macro\raiseboxzerothat does that by working on\raisebox's definition, but perhaps there is a more elegant solution. – Pedro Sánchez Terraf Dec 06 '18 at 00:36\makeatletter \long\def\raiseboxzero#1#2{\@begin@tempboxa\hbox{#2}\setlength\@tempdima{#1}\setlength\@tempdimb{0pt}\setbox\@tempboxa\hbox{\raise\@tempdima\box\@tempboxa}\ht\@tempboxa\@tempdimb\box\@tempboxa\@end@tempboxa} \makeatotherand then I replace\raiseboxin your definition by\raiseboxzero. (I'm having trouble to put it in a codeblock.) – Pedro Sánchez Terraf Dec 06 '18 at 00:40\raisebox{\baselineskip}{…}by\raisebox{\baselineskip}[0pt]{…}(the optional argument is the height of the final box). – Circumscribe Jan 25 '19 at 12:08