答案1
您可以进行修补\@wrindex
以使用特殊计数器。
在这里我嘲笑您的设置,并根据您的设置进行调整。
\documentclass{book}
\usepackage{imakeidx}
\usepackage{xpatch}
\makeindex
\newcounter{legalsection}[chapter]
\renewcommand{\thelegalsection}{\thechapter-\threedigits{legalsection}}
\newcommand{\threedigits}[1]{%
\ifnum\value{#1}<10 0\fi
\ifnum\value{#1}<100 0\fi
\arabic{#1}%
}
\newcommand{\legalsection}{%
\par
\noindent
\refstepcounter{legalsection}%
\makebox[0pt][l]{\hspace*{\textwidth}\quad\textbf{\thelegalsection}}%
}
%%%% This is the main part!
\makeatletter
\patchcmd{\@wrindex}{\thepage}{\thelegalsection}{}{}
\makeatother
%%%%
\begin{document}
\chapter{First}
\legalsection
(a) This is the first section where we deal with apples\index{apple}.
\legalsection
(b) This is the second section where we deal with bananas\index{banana}.
\chapter{Second}
\legalsection
Here we deal with cherries\index{cherry}
\printindex
\end{document}