我是这样做的:
\begin{filecontents*}{Idx.ist}
headings_flag 1
heading_prefix "{\\hrulefill \n \n \\textbf{"
heading_suffix "}} \\nopagebreak"
delim_0 "\n\n \\item "
group_skip "\n\n \\hrulefill"
\end{filecontents*}
\documentclass[8.5pt twoside, a4paper]{book}
\let\cleardoublepage\clearpage
\usepackage[T1]{fontenc}
\usepackage[german]{babel}
\usepackage[utf8]{inputenc}
\usepackage[scaled]{uarial}
\renewcommand{\familydefault}{\sfdefault}
\usepackage{multicol}
\usepackage{titlesec}
\usepackage{imakeidx}
\usepackage{hyperref}
\makeindex[options=-s Idx.ist]
\makeatletter
\let\mygobble\@gobble
\LetLtxMacro\OldIndex\index
\renewcommand{\index}[1]{\OldIndex{#1|mygobble}}
\makeatother
\begin{document}
\chapter{Test}
Irgendein Text.
\section{Eins}
Blablabla.
\subsection{Regeln}
\index{Ausland}
\index{Sieger}
\index{Spieler}
\index{Spielfeld}
\subsection{Beschäftigung}
\index{Beruf}
\index{Arbeit}
\vfill
\pagebreak
\addcontentsline{toc}{section}{\textbf{Stichwortverzeichnis}}
\renewcommand{\indexname}{Stichwortverzeichnis}
\fontsize{7.5pt}{0pt}
\printindex
\end{document}
编辑:章节编号和末尾带有一行的东西工作正常!谢谢!
但缩进不起作用。\struntbox
不起作用。
编辑 2.0:如果我有更多索引,则字母字符“组”内会出现列分隔符。我该如何避免这种情况?
如何添加这样的行?
答案1
如果您想要索引处的页码,只需不要通过重新定义 来删除它们。可以通过对 进行一些更改和一些附加定义来\index
完成格式化:Idx.ist
\RequirePackage{filecontents}
\begin{filecontents*}{Idx.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*}
\documentclass[8.5pt,% book does not know this option (but don't forget the comma!)
twoside,% this is default
openany,% so usually you do not need \let\cleardoublepage\clearpage
a4paper]{book}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel} % use new spelling instead of old
\usepackage[utf8]{inputenc}
%\usepackage[scaled]{uarial}% uarial is a very ugly mix of Arial and Helvetica
\renewcommand{\familydefault}{\sfdefault}
\usepackage{multicol}
\usepackage{titlesec}
\usepackage{imakeidx}
\usepackage{hyperref}
\makeindex[options=-s Idx.ist]
% If you do not want page numbers but, e.g. subsection numbers in the index:
%\LetLtxMacro\OldIndex\index
%\newcommand*{\indexpage}[2]{#1}
%\renewcommand{\index}[1]{\OldIndex{#1|indexpage{\thesubsection}}}
\newcommand*{\indexheading}[1]{%
\indexrule
\textbf{#1}\par
\nopagebreak
\vskip-\baselineskip% go back to the heading line
}
\newcommand*{\indexrule}{%
\par\nopagebreak
\vskip-\ht\strutbox
\hrulefill\par\pagebreak[3]
\vskip -\baselineskip
\hrulefill\par\nobreak
}
\newcommand*{\starttheindex}{\raggedcolumns}
\newcommand*{\stoptheindex}{\indexrule}
\makeatletter
\renewcommand*{\@idxitem}{\par\hangindent 2em\hskip 1.5em}% indent the entry
\makeatother
\begin{document}
\chapter{Test}
Irgendein Text.
\section{Eins}
Blablabla.
\subsection{Regeln}
\index{Ausland}
\index{Sieger}
\index{Spieler}
\index{Spielfeld}
\subsection{Beschäftigung}
\index{Beruf}
\index{Arbeit}
\vfill
\clearpage% should be used before \addcontentsline
\addcontentsline{toc}{chapter}{Stichwortverzeichnis}% the index is a chapter and becomes the font for chapter entries that is already bold
\renewcommand{\indexname}{Stichwortverzeichnis}
\fontsize{7.5pt}{0pt}
\printindex
\end{document}
如果你删除%
前面的
\LetLtxMacro\OldIndex\index
\newcommand*{\indexpage}[2]{#1}
\renewcommand{\index}[1]{\OldIndex{#1|indexpage{\thesubsection}}}
你会得到:
为了避免组内的列中断,您可以\nopagebreak
在定义中添加附加内容\@idxitem
:
\RequirePackage{filecontents}
\begin{filecontents*}{Idx.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*}
\documentclass[8.5pt,% book does not know this option (but don't forget the comma!)
twoside,% this is default
openany,% so usually you do not need \let\cleardoublepage\clearpage
a4paper]{book}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel} % use new spelling instead of old
\usepackage[utf8]{inputenc}
%\usepackage[scaled]{uarial}% uarial is a very ugly mix of Arial and Helvetica
\renewcommand{\familydefault}{\sfdefault}
\usepackage{multicol}
\usepackage{titlesec}
\usepackage{imakeidx}
\usepackage{hyperref}
\makeindex[options=-s Idx.ist]
% If you do not want page numbers but, e.g. subsection numbers in the index:
%\LetLtxMacro\OldIndex\index
%\newcommand*{\indexpage}[2]{#1}
%\renewcommand{\index}[1]{\OldIndex{#1|indexpage{\thesubsection}}}
\newcommand*{\indexheading}[1]{%
\indexrule
\textbf{#1}\par
\nopagebreak
\vskip-\baselineskip% go back to the heading line
}
\newcommand*{\indexrule}{%
\par\nopagebreak
\vskip-\ht\strutbox
\hrulefill\par\pagebreak[3]
\vskip -\baselineskip
\hrulefill\par\nobreak
}
\newcommand*{\starttheindex}{\raggedcolumns}
\newcommand*{\stoptheindex}{\indexrule}
\makeatletter
\renewcommand*{\@idxitem}{\par\nopagebreak\hangindent 2em\hskip 1.5em}% indent the entry
\makeatother
\begin{document}
\chapter{Test}
Irgendein Text.
\section{Eins}
Blablabla.
\subsection{Regeln}
\index{Ausland}
\index{Sieger}
\index{Spieler}
\index{Spielfeld}
\subsection{Beschäftigung}
\index{Beruf}
\index{Arbeit}
\index{Test1}\index{Test2}\index{Test3}\index{Test4}\index{Test5}
\index{Test6}\index{Test7}\index{Test8}\index{Test9}\index{Test10}
\vfill
\clearpage% should be used before \addcontentsline
\addcontentsline{toc}{chapter}{Stichwortverzeichnis}% the index is a chapter and becomes the font for chapter entries that is already bold
\renewcommand{\indexname}{Stichwortverzeichnis}
\fontsize{7.5pt}{0pt}
\printindex
\end{document}
但我不建议这样做,因为如果组大于列高,则将得到过满的列。
要更改规则上方的垂直距离,只需更改行
\vskip-\ht\strutbox
在 的定义中\indexrule
,例如,
\newcommand*{\indexrule}{%
\par\nopagebreak
\vskip\dp\strutbox\nopagebreak
\hrulefill\par\pagebreak[3]
\vskip -\baselineskip
\hrulefill\par\nobreak
}
会导致
请注意,我使用了另一种字体,因为我没有安装丑陋的 URW-Arial。
您还应该看看我添加到代码中的几条注释。