2

First an MWE and its index page are as follows.

\documentclass[12pt]{article}

%%%index setting%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{imakeidx}
\usepackage[colorlinks,linkcolor=blue]{hyperref}
\usepackage[columns=2,columnsep=2em,%rule=0pt,
initsep=1\baselineskip plus 0.2ex minus 0.1ex,%
hangindent=1em,subindent=1em,hangindent=1em,subsubindent=2em]
{idxlayout}%must be after imakeidx

%Index format-----------------------------------------
\usepackage{filecontents}
\begin{filecontents}[overwrite]{\jobname.mst}
headings_flag 1
heading_prefix "{\\bfseries "
    heading_suffix "}\\nopagebreak\n"
delim_0 "\\dotfill "
delim_1 "\\dotfill "
delim_2 "\\dotfill "
delim_n "\\idxBdelim"%%change comma before 'see also' for semicolon
\end{filecontents}
\makeindex
%change comma before 'see also' for semicolon---------------
\makeatletter
\def\idxBdelim{\@ifnextchar{\hyperindexformat}{; }{, }}
\def\@commahyperpage#1{\@@commahyperpage#1\idxBdelim{}\idxBdelim{}\\}
\def\@@commahyperpage#1\idxBdelim#2\idxBdelim#3\\{%
  \ifx\\#2\\%
    \HyInd@pagelink{#1}%
  \else
    \HyInd@pagelink{#1}\idxBdelim\HyInd@pagelink{#2}%
  \fi
}
\makeatother
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


\begin{document}

some text\index{red apple} \index{alpple!red \~{}} \index{yellow!apple}\index{alpple!yellow \~{}} \index{green!apple} \index{alpple!green \~{}}with some index entries\index{white pear} \index{pear!white \~{}}

index{yellow!pear} \index{pear!yellow \~{}} \index{green!pear} \index{pear!green \~{}}
\index{yellow!many many many many many many alpple}
\index{alpple!yellow many many many many many many \~{}}

\newpage
and some\index{yellow!pear} \index{pear!yellow \~{}} \index{green!pear} \index{pear!green \~{}}\emph{see also} entries as well.

\index{red apple} \index{alpple!red \~{}} \index{yellow!apple}\index{alpple!yellow \~{}} \index{green!apple} \index{alpple!green \~{}} \index{white pear} \index{pear!white \~{}}



\newpage
\null
\index{alpple!red \~{}|seealso{red apple}}
\index{alpple!yellow \~{}|seealso{yellow apple}}
\index{alpple!yellow many many many many many many \~{}|seealso{yellow many many many many many many apple}}
\index{alpple!green \~{}|seealso{green apple}}
\index{pear!white \~{}|seealso{white pear}}
\index{pear!yellow \~{}|seealso{yellow pear}}
\index{pear!green \~{}|seealso{green pear}}

\printindex
\end{document}

enter image description here

Ass you see, the layout of mots of the index entries is well except two subentries of apple in the following. The problem also exists if there are no "see also" instructions but many page numbers.

enter image description here

So is there a way to make such long entries output as follows, i.e., every line of the entries is aligned both left and right side? By the way, I know such alignment problem on index entries is very difficult, and so any effort whether or not to solve the problem is welcome and appreciated. Thanks in advance!

enter image description here

1 Answer 1

1

I don't think it's possible to do that. Instead I have this idea to make it looks a little better.

\documentclass[12pt]{article}

%%%index setting%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{imakeidx}
\usepackage[colorlinks,linkcolor=blue]{hyperref}
\usepackage[columns=2,columnsep=2em,%rule=0pt,
initsep=1\baselineskip plus 0.2ex minus 0.1ex,%
hangindent=1em,subindent=1em,hangindent=1em,subsubindent=2em]
{idxlayout}%must be after imakeidx

%Index format-----------------------------------------
\begin{filecontents}[overwrite]{\jobname.mst}
headings_flag 1
heading_prefix "{\\bfseries "
    heading_suffix "}\\nopagebreak\n"
delim_0 "\\dotfill "
delim_1 "\\dotfill "
delim_2 "\\dotfill "
delim_n "\\idxBdelim"%%change comma before 'see also' for semicolon
delim_t ""
\end{filecontents}
\makeindex
%change comma before 'see also' for semicolon---------------
\makeatletter
\def\idxBdelim{\@ifnextchar{\hyperindexformat}{\newline\null\hfill}{, }}
\def\@commahyperpage#1{\@@commahyperpage#1\idxBdelim{}\idxBdelim{}\\}
\def\@@commahyperpage#1\idxBdelim#2\idxBdelim#3\\{%
  \ifx\\#2\\%
    \HyInd@pagelink{#1}%
  \else
    \HyInd@pagelink{#1}\idxBdelim\HyInd@pagelink{#2}%
  \fi
}
\makeatother
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


\begin{document}

some text\index{red apple} \index{alpple!red \~{}} \index{yellow!apple}\index{alpple!yellow \~{}} \index{green!apple} \index{alpple!green \~{}}with some index entries\index{white pear} \index{pear!white \~{}}

index{yellow!pear} \index{pear!yellow \~{}} \index{green!pear} \index{pear!green \~{}}
\index{yellow!many many many many many many alpple}
\index{alpple!yellow many many many many many many \~{}}

\newpage
and some\index{yellow!pear} \index{pear!yellow \~{}} \index{green!pear} \index{pear!green \~{}}\emph{see also} entries as well.

\index{red apple} \index{alpple!red \~{}} \index{yellow!apple}\index{alpple!yellow \~{}} \index{green!apple} \index{alpple!green \~{}} \index{white pear} \index{pear!white \~{}}



\newpage
\null
\index{alpple!red \~{}|seealso{red apple}}
\index{alpple!yellow \~{}|seealso{yellow apple}}
\index{alpple!yellow many many many many many many \~{}|seealso{yellow many many many many many many apple}}
\index{alpple!green \~{}|seealso{green apple}}
\index{pear!white \~{}|seealso{white pear}}
\index{pear!yellow \~{}|seealso{yellow pear}}
\index{pear!green \~{}|seealso{green pear}}

\printindex
\end{document}

enter image description here

1
  • It seems to solve no problem. Thanks anyway!
    – M. Logic
    Jun 3, 2022 at 2:29

You must log in to answer this question.

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