我可以按字母顺序打印索引。但是,如果我在索引条目中使用 \ref,子条目将不按字母顺序排列。我希望模块 3 条目位于模块 2 条目之后。我如何告诉 LaTeX 按章节编号而不是章节名称进行排序/按字母顺序排列?
以下是 MWE:
\documentclass[twoside,openright,12pt]{report}
\def\usletterpaper{\usepackage[bottom=1in,hmarginratio=1:1,letterpaper]{geometry}}
\usepackage{makeidx}
\makeindex
\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%
\chapter{Node Management} \label{chap:NodeMgmt}
Chapter text here.
\section{Learning Check}
\index{Learning Check!Module~\ref{chap:NodeMgmt}}
Question\\
Answer\\
\section{Learning Check Answer}
\index{Learning Check Answers!Module~\ref{chap:NodeMgmt}@Module~\ref{chap:NodeMgmt}}
Question\\
Answer\\
%%%%%%%%%%%%%%%%%%%%%%%%%%
\chapter{User Management} \label{chap:UserMgmt}
Chapter text here.
\section{Learning Check}
\index{Learning Check!Module~\ref{chap:UserMgmt}}
Question\\
Answer\\
\section{Learning Check Answer}
\index{Learning Check Answers!Module~\ref{chap:UserMgmt}}
Question\\
Answer\\
Question\\
Answer\\
%%%%%%%%%%%%%%%%%%%%
\chapter{Application Management} \label{chap:AppMgmt}
Chapter text here.
\section{Learning Check}
\index{Learning Check!Module \ref{chap:AppMgmt} @Module~\thechapter}
Question\\
Answer\\
\section{Learning Check Answer}
\index{Learning Check Answers!Module~\ref{chap:AppMgmt}@Module\ref{chap:AppMgmt}}
Question\\
Answer\\
\printindex
\end{document}
答案1
问题在于,\ref
在发送到文件时 s 不会被展开.idx
。因此,条目不是按数字排序的,而是按 的内容排序的\ref
,第一个条目是\ref{chap:AppMgmt}
,最终将导致 Module 3。
必须做的是在将引用发送到文件之前对其进行扩展.idx
。这可以通过 来完成\newcommand{\myindex}[1]{\expandafter\index\expandafter{#1}}
。然后更改每个 都将得到所需的输出\index
。\myindex
\documentclass[twoside,openright,12pt]{report}
\def\usletterpaper{\usepackage[bottom=1in,hmarginratio=1:1,letterpaper]{geometry}}
\usepackage{makeidx}
\makeindex
\newcommand{\myindex}[1]{\expandafter\index\expandafter{#1}}
\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%
\chapter{Node Management} \label{chap:NodeMgmt}
Chapter text here.
\section{Learning Check}
\myindex{Learning Check!Module~\ref{chap:NodeMgmt}}
Question\\
Answer\\
\section{Learning Check Answer}
\myindex{Learning Check Answers!Module~\ref{chap:NodeMgmt}@Module~\ref{chap:NodeMgmt}}
Question\\
Answer\\
%%%%%%%%%%%%%%%%%%%%%%%%%%
\chapter{User Management} \label{chap:UserMgmt}
Chapter text here.
\section{Learning Check}
\myindex{Learning Check!Module~\ref{chap:UserMgmt}}
Question\\
Answer\\
\section{Learning Check Answer}
\myindex{Learning Check Answers!Module~\ref{chap:UserMgmt}}
Question\\
Answer\\
Question\\
Answer\\
%%%%%%%%%%%%%%%%%%%%
\chapter{Application Management} \label{chap:AppMgmt}
Chapter text here.
\section{Learning Check}
\myindex{Learning Check!Module~\ref{chap:AppMgmt}@Module~\thechapter}
Question\\
Answer\\
\section{Learning Check Answer}
\myindex{Learning Check Answers!Module~\ref{chap:AppMgmt}@Module~\ref{chap:AppMgmt}}
Question\\
Answer\\
\printindex
\end{document}