索引:在 \section 和 \subsection 中使用 \index 的顺序错误和问题

索引:在 \section 和 \subsection 中使用 \index 的顺序错误和问题

我的 .tex 文件中的索引有两个问题。 在此处输入图片描述

1) 我怎样才能将 1.10 放在 1.3 后面?2) 我怎样才能将 \section 中的零隐藏起来?(例如,用 1 代替 1.0)

不幸的是我的 MWE 并不是那么“最小”:

\documentclass{scrbook}

\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage[linktoc=none]{hyperref}
\usepackage{imakeidx}

\renewcommand\thesection{\arabic{section}} 

\makeindex 
\LetLtxMacro\OldIndex\index
\newcommand*{\indexpage}[2]{#1}
\renewcommand{\index}[1]{\OldIndex{#1|indexpage{\thesubsection}}} 


\begin{document}
\section{English football league system}
\index{System}
%
\subsection{History}
Created in 1888.
%
\subsection{Structure}
\index{Structure}
At the top is the single division of the Premier League
%
\subsection{Cup eligibility}
\index{Cup}
Being members of a league at a particular level also affects eligibility for Cup.
%
\subsection{Sub 4}
%
\subsection{Sub 5}
%
\subsection{Sub 6}
%
\subsection{Sub 7}
%
\subsection{Sub 8}
%
\subsection{Sub 9}
%
\subsection{Carobao Cup}
\index{Cup}


\printindex
\end{document}

答案1

您可以添加前导零以便进行索引排序,然后在排版时删除它们

在此处输入图片描述

\documentclass{scrbook}

\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage[linktoc=none]{hyperref}
\usepackage{imakeidx}

\renewcommand\thesection{\arabic{section}} 

\makeindex 
\LetLtxMacro\OldIndex\index
\newcommand*{\indexpage}[5]{#2\ifnum#4=0 \else.#4\fi}
\renewcommand{\index}[1]{\OldIndex{#1|%
   indexpage
    {\ifnum\value{section}<10 0\fi}{\arabic{section}}%
    {\ifnum\value{subsection}<10 0\fi}{\arabic{subsection}}}%
}

\begin{document}
\section{English football league system}
\index{System}
%
\subsection{History}
Created in 1888.
%
\subsection{Structure}
\index{Structure}
At the top is the single division of the Premier League
%
\subsection{Cup eligibility}
\index{Cup}
Being members of a league at a particular level also affects eligibility for Cup.
%
\subsection{Sub 4}
%
\subsection{Sub 5}
%
\subsection{Sub 6}
%
\subsection{Sub 7}
%
\subsection{Sub 8}
%
\subsection{Sub 9}
%
\subsection{Carobao Cup}
\index{Cup}


\printindex
\end{document}

相关内容