如果有太多部分具有相同的 \index,则下一行将显示一些索引引用。这很好,但我想将其对齐到右侧(如下图所示)。我该怎么做?我想我应该替换 in,\hangindent 2em
但
\renewcommand*{\@idxitem}{\par\nopagebreak\hangindent 2em\hskip 0.8cm}
我不知道该怎么做。
\documentclass{scrbook}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage[linktoc=none]{hyperref}
\usepackage{imakeidx}
\renewcommand\thesection{\arabic{section}}
\RequirePackage{filecontents}
\begin{filecontents*}{Index.ist}
headings_flag 1
heading_prefix "\\indexheading{"
heading_suffix "}"
delim_0 "\\hfill"
group_skip "\n"
preamble "\\begin{theindex}\\starttheindex"
postamble "\n\\stoptheindex\\end{theindex}"
\end{filecontents*}
\usepackage{imakeidx}
\makeindex[options=-s Index.ist, columnsep=5mm]
\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}}}%
}
\newcommand*{\indexheading}[1]{%
\indexrule
\hspace*{1mm}\textbf{#1}\par
\nopagebreak
\vskip-\baselineskip
}
\newcommand*{\indexrule}{%
\par\nopagebreak
\vskip\dp\strutbox\nopagebreak
\hrulefill\par\pagebreak[3]
\vskip -\baselineskip
\hrulefill\par\nobreak
}
\newcommand*{\starttheindex}{\raggedcolumns}
\newcommand*{\stoptheindex}{\indexrule}
\makeatletter
\renewcommand*{\@idxitem}{\par\nopagebreak\hangindent 2em\hskip 0.8cm}
\makeatother
\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}
\index{Cup}
%
\subsection{Sub 5}
\index{Cup}
%
\subsection{Sub 6}
\index{Cup}
%
\subsection{Sub 7}
\index{Cup}
%
\subsection{Sub 8}
\index{Cup}
%
\subsection{Sub 9}
\index{Cup}
%
\subsection{Carabao Cup}
\index{Cup}
\printindex
\end{document}
答案1
我可以使用 \raggedright 和 \raggedleft 解决这个问题。
\documentclass{scrbook}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage[linktoc=none]{hyperref}
\usepackage{imakeidx}
\renewcommand\thesection{\arabic{section}}
\RequirePackage{filecontents}
\begin{filecontents*}{Index.ist}
headings_flag 1
heading_prefix "\\indexheading{"
heading_suffix "}"
delim_0 "\\hfill"
group_skip "\n"
preamble "\\begin{theindex}\\starttheindex"
postamble "\n\\stoptheindex\\end{theindex}"
\end{filecontents*}
\usepackage{imakeidx}
\makeindex[options=-s Index.ist, columnsep=5mm]
\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}}}%
}
\newcommand*{\indexheading}[1]{%
\indexrule
\raggedright\hspace*{1mm}\textbf{#1}\par % NEW CODE (with\raggedright)
\nopagebreak
\vskip-\baselineskip
}
\newcommand*{\indexrule}{%
\par\nopagebreak
\vskip\dp\strutbox\nopagebreak
\hrulefill\par\pagebreak[3]
\vskip -\baselineskip
\hrulefill\par\nobreak
}
\newcommand*{\starttheindex}{\raggedcolumns}
\newcommand*{\stoptheindex}{\indexrule}
\makeatletter
\renewcommand*{\@idxitem}{\par\nopagebreak\hangindent 2em\raggedleft\hskip 0.8cm} % NEW CODE (with \raggedleft)
\makeatother
\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}
\index{Cup}
%
\subsection{Sub 5}
\index{Cup}
%
\subsection{Sub 6}
\index{Cup}
%
\subsection{Sub 7}
\index{Cup}
%
\subsection{Sub 8}
\index{Cup}
%
\subsection{Sub 9}
\index{Cup}
%
\subsection{Carabao Cup}
\index{Cup}
\printindex
\end{document}