如何使用 imakeidx 包创建按字母顺序排列的索引?

如何使用 imakeidx 包创建按字母顺序排列的索引?

我正在创建一个论文模板

我在制作索引时遇到的问题是我想要生成如下所示的索引页:

Index

P
Picard, 2

W
Warp factor, 11

现在它看起来像: 索引页:标题索引,条目 1- Picard,第 2 页,条目 2- Warp Factor,第 11 页

相关代码来自序言.tex看起来像这样:

\usepackage{imakeidx} % Package for creating index
% Activate hyperlinks for the index
\makeindex[columns=2, title=Index, intoc=true]

索引条目位于第一章.tex第02章.tex作为:

\index{Picard}
\index{Warp Factor}

索引最终打印在主文本作为:

% Index
\clearpage
\phantomsection % To correct the anchor toc index to the index page. Otherwise, the toc index takes user to the last section of the appendix chapter before this.
\printindex % Print the index

任何解决方案都将不胜感激。

编辑 - 2024 年 3 月 16 日晚上 9 点(欧洲中部时间):

更新的 MWE:

主文件的位置是src/main.tex

\documentclass[12pt]{book}

\input{src/contents/latex_doc_preamble/preamble.tex}

\begin{document}
    \frontmatter
    \maketitle
    \tableofcontents

    \mainmatter
    \part{Part 1}

    \chapter{Chapter 01}
    \section{section 1}
    \paragraph*{}
    \blindtext \index{Picard} Picard.

    \chapter{Chapter 02}
    \section{section 1}
    \paragraph*{}
    \blindtext \index{Warp Factor} Warp Factor.

    \appendix
    \chapter{Appendix title}
    \section{section 1}
    \subsection{}
    \paragraph*{}
    \blindtext

    \clearpage
    \phantomsection % To correct the anchor toc index
    \printindex % Print the index

\end{document}

序言文件的位置是src/contents/latex_doc_preamble/preamble.tex

\title{MWE}
\author{Some Author}

\usepackage{blindtext} % Generates dummy text for testing purposes
\usepackage{imakeidx} % Package for creating index
% \makeindex[columns=2, title=Index, intoc=true]
\makeindex[columns=2, title=Index, intoc=true,options=-s myindexstyle]
\usepackage{tocbibind} % Include table of contents, list of figures, etc., in table of contents
\usepackage[hidelinks]{hyperref} % Enhancements for hyperlinks and cross-references

编译后的pdf文件位置将是并使用以下命令build/main.pdf进行编译:latexmk

latexmk -pdf -output-directory=build src/main.tex

答案1

对于这张糟糕的图像,我们深表歉意,它是 Okular/KDE 最新版本的一个功能。

索引按字母等分开

imakeidx文档第 15-16 页:

\begin{filecontents}[overwrite]{myindexstyle.ist}
headings_flag 1
heading_prefix
 "\\bigskip\\par\\penalty-50\\textbf{"
heading_suffix
 "}\\\\[\\medskipamount]"
symhead_positive "Symbols"
symhead_negative "symbols"
numhead_positive "Numbers"
numhead_negative "numbers"
delim_0 ",\~"
\end{filecontents}

\documentclass[12pt]{book}

\title{MWE}
\author{Some Author}

\usepackage{blindtext} % Generates dummy text for testing purposes
\usepackage{imakeidx} % Package for creating index
\makeindex[columns=2, title=Index, intoc=true,options=-s myindexstyle]
\usepackage{tocbibind} % Include table of contents, list of figures, etc., in table of contents
\usepackage[hidelinks]{hyperref} % Enhancements for hyperlinks and cross-references

\begin{document}
\frontmatter
\maketitle
\tableofcontents

\mainmatter
\part{Part 1}

\chapter{Chapter 01}
\section{section 1}
\paragraph*{}
\blindtext \index{Picard} Picard.

\chapter{Chapter 02}
\section{section 1}
\paragraph*{}
\blindtext \index{Warp Factor} Warp Factor.

\appendix
\chapter{Appendix title}
\section{section 1}
\subsection{}
\paragraph*{}
\blindtext

\clearpage
\phantomsection % To correct the anchor toc index to the index page. Otherwise, the toc index takes user to the last section of the appendix chapter before this.
\printindex % Print the index

\end{document}

相关内容