我就是這樣做的:
\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
不起作用..
Edit2.0:如果我有更多的indeces,則字母字元「群組」內有一個分欄符。我怎樣才能避免這種情況?
第三次編輯:我剛剛意識到在群組之後我需要額外的行/行。像這樣:
如何加入這樣的行/線?
答案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。
您還應該查看我添加到程式碼中的幾個註釋。