如何在沒有頁碼的情況下為項目層級的索引新增條目?

如何在沒有頁碼的情況下為項目層級的索引新增條目?

在我的索引中,我想將某些項目分組到群組條目名稱下。由於我已經使用了三個可用層級(項目、子項目、子子項目),因此我嘗試建立一個沒有頁碼的條目。在下面的範例中,「Weird Languages」後面不應跟頁碼,因為它旨在作為後續內容的類別標題。

 \documentclass[12pt,twoside,a4paper,openright]{book}

 \usepackage{xunicode}
 \usepackage{imakeidx} 
 \makeindex[name=texts,title=Texts,columns=1,options=-s mystyle -c -l] 
 \begin{document}

 \index[texts]{Script@\string\textbf{Weird Languages}}

 3.28\index[texts]{Script!Aramaic!3.28}
 5.1\index[texts]{Script!Greek!5.1}
 8.1\index[texts]{Script!Demotic!8.1}

 \printindex[texts]

 \end{document}

到目前為止的結果是:

PDF輸出

如何抑制單一條目的頁碼,此處為“奇怪的語言”,或者如何添加沒有頁碼的項目,同時保持其他項目的頁碼正常?

答案1

這是一個當我使用它時有效的技巧。

在序言中加入以下定義:

\newcommand{\idxnopage}[1]{{}}
\providecommand{\gobble}[1]{{}}
\newcommand{\idxsechead}[1]{\textbf{#1}\gobble}

像這樣使用它,插入適當的排序參數和文字:

\index{<sort argument>@\idxsechead{<header text>} |idxnopage}

我一直無法想出一個包含\idxnopage. (也許 david 或egreg 可以改進這一點。)

編輯:這是一個小範例,它將產生上述輸出。請注意,必須運行第一次 Latex 運行生成的makeindex文件.idx,然後透過 Latex 再次處理該.tex文件以實際在輸出中包含索引。

\documentclass{article}
\usepackage{makeidx}
\newcommand{\idxnopage}[1]{{}}
\providecommand{\gobble}[1]{{}}
\newcommand{\idxsechead}[1]{\textbf{#1}\gobble}
\makeindex

\begin{document}
Here is some text\index{some text} that we want indexed.

We also want a ``header'' in the index.
\index{00@\idxsechead{Header} |idxnopage}
\printindex
\end{document}

答案2

只是為了概念證明。使用.ind上面給出的範例文件產生的文件,您有:

\begin{theindex}

  \item Script
    \subitem Aramaic
      \subsubitem 3.28, 1
    \subitem Demotic
      \subsubitem 8.1, 1
    \subitem Greek
      \subsubitem 5.1, 1
  \item \string, \textbf{Weird Languages}{1}

\end{theindex}

如果你把它改成:

\begin{theindex}

  \item \textbf{Weird Languages}
  \item Script
    \subitem Aramaic
      \subsubitem 3.28, 1
    \subitem Demotic
      \subsubitem 8.1, 1
    \subitem Greek
      \subsubitem 5.1, 1

\end{theindex}

並使用選項再運行xelatex一次,您將得到 'noautomaticimakeidx奇怪的語言' 位於「腳本」之上且處於同一級別,但沒有頁面引用。對於一兩次一次性編輯來說,這非常簡單。

相關內容