Index formatting
From
Holger Schieferdecker@21:1/5 to
All on Wed Dec 13 15:40:02 2023
Hi,
recently I tried to format an index created with makeindex. I wanted to
right align the page numbers and fill the gap with dots. For that I
found a solution at TeX stackexchange. Then I also wanted centered
capital letters (A, B, and so on) for each group in the index. I also
found a solution for that, but I had to try several ways. And I don't
fully understand why some ways don't work. Maybe someone can explain
that. A working example is below.
What I tried are the following alternatives.
\hfil\textbf{#1}\hfil% this is just indented
% \hfil\hfil\textbf{#1}\hfil% this is centered, but why
% \hfil\textbf{#1}% this is centered, but why?
% \hfill\textbf{#1}\hfill% this centered
% \hfill\textbf{#1}% right-aligned, as expected
I understand that \hfil and \hfill internally have different
glues/stretches (fil vs. fill). It seems that something else is adding a
fil after the heading, so effectively there is something like
fil "Letter" fil fil
But I don't see where that additional fil could come from. Removing \belowpdfbookmark or nopagebreak didn't change anything.
As the line with \hfill\textbf{#1}\hfill works this question is more of academic interest. :-)
Holger
%%%%%%%%%%%%%%%%%%%%%%%%
\documentclass{scrreprt}
\KOMAoption{parskip}{half-}
\KOMAoption{index}{totoc}
\usepackage{xcolor}
\usepackage{makeidx}
\usepackage{hyperref}
\hypersetup{colorlinks}
\hypersetup{linkcolor=blue}
\usepackage{bookmark}
\bookmarksetup{numbered}
\bookmarksetup{open}
\bookmarksetup{openlevel=3}
% format settings for index
\begin{filecontents*}[overwrite]{\jobname.mst}
headings_flag 1
heading_prefix "\\IndexHeading{"
heading_suffix "}\\nopagebreak\n"
delim_0 "\\IndexFill "
delim_1 "\\IndexFill "
\end{filecontents*}
% format index heading and put it into bookmarks \newcommand*{\IndexHeading}[1]{%
\hfil\textbf{#1}\hfil% this is just indented
% \hfil\hfil\textbf{#1}\hfil% this is centered, but why
% \hfil\textbf{#1}% this is centered, but why?
% \hfill\textbf{#1}\hfill% this centered
% \hfill\textbf{#1}% right-aligned, as expected
\belowpdfbookmark{#1}{#1}%
}
% right-align page numbers in index, fill with dots
\ExplSyntaxOn
\newcommand*{\IndexFill}{%
\leaders \hbox to .67em {\hss \textcolor{gray!55}{.} \hss}\hfill
}
\ExplSyntaxOff
\makeindex
\begin{document}
\pdfbookmark[1]{\contentsname}{toc}
\tableofcontents % Inhaltsverzeichnis
\chapter{Fruits}
\index{Apple}
\index{Banana}
The topic is fruits.
\printindex
\end{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)