名称索引和术语索引不被识别为章节

名称索引和术语索引不被识别为章节

首先,MWE 及其内容和索引页的输出如下。

\documentclass{book}

\usepackage{imakeidx}
\usepackage{hyperref}
\usepackage[totoc=true]{idxlayout}

\indexsetup{level=\section*,toclevel=section,noclearpage}
\makeindex[name=name,title=Index of Names,options=-s mystyle2.ist]
\makeindex[title=Index of Terms]


\begin{document}
\tableofcontents
\chapter{Test}

This is it\index{important function important function important function}.

\index{many}

That's all, Legend Green! \index[name]{Green, Legend}

\index{new}

OK! \index{very beautiful word involving only two letters}

\cleardoublepage\phantomsection
\chapter*{Indices}
\addcontentsline{toc}{chapter}{Indices}

\printindex[name]

\printindex

\end{document}

在此处输入图片描述

在此处输入图片描述

在此处输入图片描述

如您所见,“名称索引”和“术语索引”是 pdf 中的章节,而我希望它们作为“索引”的部分。所以我设置

\indexsetup{level=\section*,toclevel=section,noclearpage}

但它不起作用。

那么,有没有办法让“名称索引”和“术语索引”按照文档的要求成为imakeidx之前调用的部分(另见idxlayoutidxlayout链接)?

答案1

idxlayout提供设置级别的可能性,一旦您使用它,相关的选项\indexsetup就没用了。

肮脏的伎俩:本地取消定义\chapter,因此idxlayout将使用\section*

\documentclass{book}

\usepackage{imakeidx}
\usepackage[totoc=true]{idxlayout}
\usepackage{hyperref}

\makeindex[name=name,title=Index of Names]%,options=-s mystyle2.ist]
\makeindex[title=Index of Terms]
\indexsetup{noclearpage}

\begin{document}

\tableofcontents

\chapter{Test}

This is it\index{important function important function important function}.

\index{many}

That's all, Legend Green! \index[name]{Green, Legend}

\index{new}

OK! \index{very beautiful word involving only two letters}

\cleardoublepage\phantomsection
\chapter*{Indices}
\addcontentsline{toc}{chapter}{Indices}

% dirty trick starts
\begingroup
\let\chapter\relax

\printindex[name]

\printindex
\endgroup
% dirty trick ends

\end{document}

目录

在此处输入图片描述

指数

在此处输入图片描述

答案2

似乎这个比证明索引条目存在问题

\usepackage{xpatch}
\makeatletter
\xpatchcmd\ila@prologue
  {\addcontentsline{toc}{chapter}{\indexname}}
  {\addcontentsline{toc}{section}{\indexname}}
  {}{\PatchFailed}
\xpatchcmd\ila@prologue
  {\chapter*}
  {\section*}
  {}{\PatchFailed}
\makeatother

完整示例

\documentclass{book}

\usepackage{imakeidx}
\usepackage{hyperref}
\usepackage[totoc=true]{idxlayout}

\indexsetup{toclevel=section,noclearpage}
\makeindex[name=name,title=Index of Names,options=-s mystyle2.ist]
\makeindex[title=Index of Terms]

\usepackage{xpatch}
\makeatletter
\xpatchcmd\ila@prologue
  {\addcontentsline{toc}{chapter}{\indexname}}
  {\addcontentsline{toc}{section}{\indexname}}
  {}{\PatchFailed}
\xpatchcmd\ila@prologue
  {\chapter*}
  {\section*}
  {}{\PatchFailed}
\makeatother

\begin{document}
\tableofcontents
\chapter{Test}

This is it\index{important function important function important function}.

\index{many}

That's all, Legend Green! \index[name]{Green, Legend}

\index{new}

OK! \index{very beautiful word involving only two letters}

\cleardoublepage\phantomsection
\chapter*{Indices}
\addcontentsline{toc}{chapter}{Indices}

\printindex[name]

\printindex

\end{document}

摘自 Overleaf.com、texlive2021

目录部分 索引部分

相关内容