首先一个MWS,其输出如下。
\documentclass[a4paper, 10pt]{book}
\usepackage{hyperref}
\usepackage{imakeidx}
\makeindex
\usepackage{filecontents}
\begin{filecontents}{\jobname.mst}
headings_flag 1 %
heading_prefix "{\\bfseries "
heading_suffix "}\\nopagebreak\n"
\addcontentsline{toc}{section}{headings_flag}
\end{filecontents}
\begin{document}
\tableofcontents
\index{And}
\index{Book}
\index{Summer}
\index{Latex}
\pagebreak
\addcontentsline{toc}{chapter}{Index}
\printindex
\end{document}
因为我想将索引字母添加到目录中,所以我\\addcontentsline{toc}{section}
按heading_prefix
如下方式添加。
\documentclass[a4paper, 10pt]{book}
\usepackage{hyperref}
\usepackage{imakeidx}
\makeindex
\usepackage{filecontents}
\begin{filecontents}{\jobname.mst}
headings_flag 1 %
heading_prefix "{\\bfseries\\addcontentsline{toc}{section} "
heading_suffix "}\\nopagebreak\n"
\addcontentsline{toc}{section}{headings_flag}
\end{filecontents}
\begin{document}
\tableofcontents
\index{And}
\index{Book}
\index{Summer}
\index{Latex}
\pagebreak
\addcontentsline{toc}{chapter}{Index}
\printindex
\end{document}
如你所见,索引字母在正常字体中出现在目录中,而不再出现在“索引”中。那么,有没有正确的方法来制作索引字母
- 发生在正常面部的TOC中,但仍
- 在“索引”中以粗体显示?
答案1
您可以定义一个新命令来处理heading_suffix
(见下文),并在您的文件\AddIndexLetterToTOC
中使用它。.mst
\documentclass[a4paper, 10pt]{book}
\usepackage{hyperref}
\usepackage{imakeidx}
\makeindex
\newcommand{\AddIndexLetterToTOC}[1]{\textbf{#1}\phantomsection\addcontentsline{toc}{section}{#1}}
\usepackage{filecontents}
\begin{filecontents*}[overwrite]{\jobname.mst}
headings_flag 1 %
heading_prefix "\\AddIndexLetterToTOC{"
heading_suffix "}\\nopagebreak\n"
\end{filecontents*}
\begin{document}
\tableofcontents
\chapter{Test chapter}
\index{And}
\index{Book}
\index{Summer}
\index{Latex}
\pagebreak
\addcontentsline{toc}{chapter}{Index}
\printindex
\end{document}