使用 idxlayout 包和 abshang 选项自定义索引样式

使用 idxlayout 包和 abshang 选项自定义索引样式

另一个问题我问如何使用选项通过idxlayout包获取自定义分隔符singlepar:我想问是否可以使用该选项保留相同的分隔符abshang,仅打印单个段落中格式化的每个条目的最后一级。

例如:

    \index{Author!Work1!1,15} 
    \index{Author!Work1!9,32}
    \index{Author!Work2!2,24} 
    \index{Author!Work2!5,11}

    \index{Author2!2,45} 
    \index{Author2!4,34}
    \index{Author2!6,12} 
    \index{Author2!9,4}

应该给出这个:

我想要的输出

以下是 MWE:

\documentclass{article}

\usepackage{fontspec}
\setmainfont{times.ttf}
\usepackage{imakeidx}
\usepackage{polyglossia}

\begin{filecontents*}{colon.ist}
delim_0 ": "
delim_1 ": "
delim_2 ": "
\end{filecontents*}

\usepackage[itemlayout=abshang]{idxlayout}

\makeatletter
\def\@idxitem{\par\addvspace{5\p@ \@plus 5\p@ \@minus 3\p@}\hangindent 40\p@}
\def\subitem{\par\hangindent 40\p@ \hspace*{20\p@}}
\def\subsubitem{\par\hangindent 40\p@ \hspace*{30\p@}}
\def\indexspace{}
\patchcmd\theindex{\indexname}{\indexname\vspace{12pt}}{}{}
\makeatother

\makeatletter
\newif\iffirstsubitem
\newif\iffirstsubsubitem
\renewcommand{\indexsubsdelim}{ }
\newcommand*{\indexsubsdelimb}{\iffirstsubsubitem\unskip\firstsubsubitemfalse\ \else --- \fi}
\renewcommand{\subitem}{\iffirstsubitem\unskip\firstsubitemfalse, \else --- \fi\firstsubsubitemtrue}%
\renewcommand{\subsubitem}{\indexsubsdelimb}%
\renewcommand{\@idxitem}{\par\setlength{\hangindent}{\ila@hangindent}\firstsubitemtrue}
\makeatother

\makeindex[options=-s colon]

\begin{document}

test

\index{Author!Work1!1,11} 
\index{Author!Work1!9,31}
\index{Author!Work2!2,21} 
\index{Author!Work2!5,12}
\index{Author!Work1!1,11} 
\index{Author!Work1!9,34}
\index{Author!Work2!2,22} 
\index{Author!Work2!5,15}
\index{Author!Work1!1,17} 
\index{Author!Work1!9,38}
\index{Author!Work2!2,27} 
\index{Author!Work2!5,14}

\index{Author2!2,45} 
\index{Author2!4,34}
\index{Author2!6,12} 
\index{Author2!9,4}
\index{Author2!2,41} 
\index{Author2!4,32}
\index{Author2!6,13} 
\index{Author2!9,5}
\index{Author2!2,46} 
\index{Author2!4,37}
\index{Author2!6,18} 
\index{Author2!9,9}

\printindex

\end{document}

谢谢你!

编辑:通过删除此行,\renewcommand{\subitem}{\iffirstsubitem\unskip\firstsubitemfalse, \else --- \fi\firstsubsubitemtrue}%我获得了具有两个子级的索引的所需输出,但具有一个子级的索引垂直堆叠(参见图片)。

在此处输入图片描述

对于 egreg:这是我正在尝试编译的文件,其中集成了您的代码。

\begin{filecontents*}{\jobname.mst}
item_0 "\n\n \\item "
item_1 " \\firstlevel "
item_2 " \\secondlevel "
item_01 " \\firstlevel "
item_x1 " \\firstlevel "
item_12 " \\secondlevel "
item_x2 " \\secondlevel "
delim_0 ":~"
delim_1 ":~"
delim_2 ":~"
\end{filecontents*}

\documentclass[a4paper, 11pt, twoside, openright]{article}

\usepackage[top=49.5mm,bottom=52.5mm,inner=39mm,outer=39mm, headheight=4mm, headsep=6mm, marginparwidth=14mm, marginparsep=2mm, nofoot]{geometry}

\usepackage[en]{metre}
\usepackage{metrix}

\usepackage{alphalph}

\usepackage[no-math]{fontspec}
\defaultfontfeatures{Ligatures={TeX, NoCommon}}
\setmainfont[SmallCapsFont=Kallimachos_SC.ttf, BoldFont=Kallimachos_Bold,ItalicFont=Kallimachos_Italic]{Leptos.ttf}
\newfontfamily\greekfont[Script=Greek]{Leptos.ttf}

\newcommand{\lts}[1]{{\addfontfeature{LetterSpace=15 plus 1 minus 1}#1}}
\newcommand{\ltsb}[1]{{\addfontfeature{LetterSpace=12 plus 1 minus 1}#1}}
\newcommand{\ltsc}[1]{{\addfontfeature{LetterSpace=10 plus 1 minus 1}#1}}
\newcommand{\grk}[1]{{\selectlanguage[variant=ancient]{greek}#1}}

\usepackage{polyglossia}
\setmainlanguage{italian}
\setotherlanguage[variant=ancient]{greek}
\setotherlanguage{german}
\setotherlanguage{english}
\setotherlanguage{latin}

\usepackage{xunicode,xltxtra}

\usepackage[figuresright]{rotating} % comando \begin{sidewaysfigure}

\usepackage{xpatch}

\usepackage{microtype}
\usepackage{comment}

\usepackage{url}
\urlstyle{rm}

\usepackage{tikz}
\usepackage{array}
\usepackage{scrextend}

\usepackage{ragged2e} 
\usepackage{hyphenat}
\usepackage{hanging} 
\usepackage{rotating}
\usepackage{lscape}
\usepackage[thinlines]{easytable}
\usepackage{makecell}
\usepackage{tabu} 
\usepackage{float}
\usepackage[export]{adjustbox}
\usepackage{caption}
\usepackage{stackrel}   
\usepackage{amsmath}
\usepackage{afterpage}

\newcommand\blankpage{%
    \null
    \thispagestyle{empty}%
    \addtocounter{page}{-1}%
    \newpage}



\usepackage{imakeidx}
\usepackage{xparse}
%\usepackage[itemlayout=singlepar]{idxlayout}

\ExplSyntaxOn
\seq_new:N \l_ale_index_item_seq
\seq_new:N \l_ale_index_subitem_seq
\tl_new:N \l_ale_index_author_tl
\tl_new:N \l_ale_index_work_tl
\dim_new:N \l_ale_index_indent_dim

\cs_set_protected:cpn { @idxitem } #1 \par
 {
  \tl_if_in:nnTF { #1 } { \firstlevel }
   {
    \tl_if_in:nnTF { #1 } { \secondlevel }
     {
      \ale_index_secondlevel:n { #1 }
     }
     {
      \ale_index_firstlevel:n { #1 }
     }
   }
   {
    \ale_index_nolevel:n { #1 }
   }
 }

\cs_new_protected:Npn \ale_index_nolevel:n #1
 {
  \seq_set_split:NVn \l_ale_index_item_seq \c_colon_str { #1 }
  \seq_pop_left:NN \l_ale_index_item_seq \l_ale_index_author_tl
  \hbox_set:Nn \l_tmpa_box { \l_ale_index_author_tl, }
  \dim_set:Nn \l_ale_index_indent_dim { \box_wd:N \l_tmpa_box }
  \par\hangindent\l_ale_index_indent_dim
  \l_ale_index_author_tl, \seq_use:Nn \l_ale_index_item_seq { }
 }
\cs_generate_variant:Nn \seq_set_split:Nnn { NV }

\cs_new_protected:Npn \ale_index_secondlevel:n #1
 {
  \seq_set_split:Nnn \l_ale_index_item_seq { \firstlevel } { #1 }
  \seq_pop_left:NN \l_ale_index_item_seq \l_ale_index_author_tl
  \l_ale_index_author_tl\par\nobreak
  \seq_map_function:NN \l_ale_index_item_seq \ale_index_subitem:n
 }
\cs_new_protected:Npn \ale_index_subitem:n #1
 {
  \seq_set_split:Nnn \l_ale_index_subitem_seq { \secondlevel } { #1 }
  \seq_pop_left:NN \l_ale_index_subitem_seq \l_ale_index_work_tl
  \hbox_set:Nn \l_tmpa_box { \qquad \l_ale_index_work_tl,~ }
  \dim_set:Nn \l_ale_index_indent_dim { \box_wd:N \l_tmpa_box }
  \par\hangindent\l_ale_index_indent_dim
  \qquad\l_ale_index_work_tl,~\seq_use:Nn \l_ale_index_subitem_seq { ~---~ }
 }

\cs_new_protected:Npn \ale_index_firstlevel:n #1
 {
  \seq_set_split:Nnn \l_ale_index_item_seq { \firstlevel } { #1 }
  \seq_pop_left:NN \l_ale_index_item_seq \l_ale_index_author_tl
  \hbox_set:Nn \l_tmpa_box { \l_ale_index_author_tl,~ }
  \dim_set:Nn \l_ale_index_indent_dim { \box_wd:N \l_tmpa_box }
  \par\hangindent\l_ale_index_indent_dim
  \l_ale_index_author_tl,~\seq_use:Nn \l_ale_index_item_seq { ~---~ }
 }


\ExplSyntaxOff

\makeindex[name=1,title=,options=-s Intero.ist]
\makeindex[name=2,title=,options=-s Intero.ist]
\makeindex[name=3,title=,options=-s Intero.ist]
\makeindex[name=4,title=,options=-s Intero.ist]
%\usepackage[itemlayout=abshang]{idxlayout}


\autorisetup{level=\subsection*,toclevel=\subsection*,noclearpage,firstpagestyle=fancy}


\newcommand*{\cose}[1]{\index[1]{#1}\ignorespaces}

\newcommand*{\parole}[1]{\index[2]{#1}\ignorespaces}

\newcommand*{\autori}[1]{\index[4]{#1}\ignorespaces}

\newcommand{\nn}[2]{#1 \textit{nt. }#1}
\newcommand{\nv}[2]{#1 \textit{nt. }#1,}
\newcommand{\qt}[1]{\textbf{#1}}

\newcommand{\pageandfn}[2]{#2 n. #1}  
\newcommand{\autorifn}[1]{\autori[1]{#1|pageandfn{\thefootnote}}}    


\usepackage[noend,noeledsec,nocritical,nofamiliar,noledgroup]{reledmac}
\usepackage[continuousnumberingwithcolumns]{reledpar}

\linenumberLevenifblanktrue

\setlength{\Lcolwidth}{0.45\textwidth}
\setlength{\Rcolwidth}{0.45\textwidth}
\columnsposition{c}
\setlength{\beforecolumnseparator}{0.05\textwidth}
\setlength{\aftercolumnseparator}{0.05\textwidth}


\usepackage{parcolumns}

\makeatletter
\newbox\mybox
\def\pcol@makenormalcol{%
  \ifvoid\footins 
  \else
\global\setbox\mybox\box\footins
   \fi
\setbox\@outputbox\box\@holdpg
  \let\@elt\relax
  \xdef\@freelist{\@freelist\@midlist}%
  \global\let\@midlist\@empty
  \@combinefloats}

\makeatother

\begin{document}


\autori{Author!Work1!1,15} 
\autori{Author!Work1!9,32}
\autori{Author!Work2!2,24} 
\autori{Author!Work2!5,11}
\autori{Author!Work1!11,42}

\autori{Author2!2,45} 
\autori{Author2!4,34}
\autori{Author2!6,12} 
\autori{Author2!9,4}
\autori{Author3}

\printindex[1]

\end{document}

答案1

一个非常不同的实现:

\begin{filecontents*}{\jobname.mst}
item_0 "\n\n \\item "
item_1 " \\firstlevel "
item_2 " \\secondlevel "
item_01 " \\firstlevel "
item_x1 " \\firstlevel "
item_12 " \\secondlevel "
item_x2 " \\secondlevel "
delim_0 ":~"
delim_1 ":~"
delim_2 ":~"
\end{filecontents*}
\documentclass{article}
\usepackage{lipsum}
\usepackage{imakeidx}
\usepackage{xparse}
%\usepackage[itemlayout=singlepar]{idxlayout}

\ExplSyntaxOn
\seq_new:N \l_ale_index_item_seq
\seq_new:N \l_ale_index_subitem_seq
\tl_new:N \l_ale_index_author_tl
\tl_new:N \l_ale_index_work_tl
\dim_new:N \l_ale_index_indent_dim

\cs_set_protected:cpn { @idxitem } #1 \par
 {
  \tl_if_in:nnTF { #1 } { \firstlevel }
   {
    \tl_if_in:nnTF { #1 } { \secondlevel }
     {
      \ale_index_secondlevel:n { #1 }
     }
     {
      \ale_index_firstlevel:n { #1 }
     }
   }
   {
    \ale_index_nolevel:n { #1 }
   }
 }

\cs_new_protected:Npn \ale_index_nolevel:n #1
 {
  \seq_set_split:NVn \l_ale_index_item_seq \c_colon_str { #1 }
  \seq_pop_left:NN \l_ale_index_item_seq \l_ale_index_author_tl
  \hbox_set:Nn \l_tmpa_box { \l_ale_index_author_tl, }
  \dim_set:Nn \l_ale_index_indent_dim { \box_wd:N \l_tmpa_box }
  \par\hangindent\l_ale_index_indent_dim
  \l_ale_index_author_tl, \seq_use:Nn \l_ale_index_item_seq { }
 }
\cs_generate_variant:Nn \seq_set_split:Nnn { NV }

\cs_new_protected:Npn \ale_index_secondlevel:n #1
 {
  \seq_set_split:Nnn \l_ale_index_item_seq { \firstlevel } { #1 }
  \seq_pop_left:NN \l_ale_index_item_seq \l_ale_index_author_tl
  \l_ale_index_author_tl\par\nobreak
  \seq_map_function:NN \l_ale_index_item_seq \ale_index_subitem:n
 }
\cs_new_protected:Npn \ale_index_subitem:n #1
 {
  \seq_set_split:Nnn \l_ale_index_subitem_seq { \secondlevel } { #1 }
  \seq_pop_left:NN \l_ale_index_subitem_seq \l_ale_index_work_tl
  \hbox_set:Nn \l_tmpa_box { \qquad \l_ale_index_work_tl,~ }
  \dim_set:Nn \l_ale_index_indent_dim { \box_wd:N \l_tmpa_box }
  \par\hangindent\l_ale_index_indent_dim
  \qquad\l_ale_index_work_tl,~\seq_use:Nn \l_ale_index_subitem_seq { ~---~ }
 }

\cs_new_protected:Npn \ale_index_firstlevel:n #1
 {
  \seq_set_split:Nnn \l_ale_index_item_seq { \firstlevel } { #1 }
  \seq_pop_left:NN \l_ale_index_item_seq \l_ale_index_author_tl
  \hbox_set:Nn \l_tmpa_box { \l_ale_index_author_tl,~ }
  \dim_set:Nn \l_ale_index_indent_dim { \box_wd:N \l_tmpa_box }
  \par\hangindent\l_ale_index_indent_dim
  \l_ale_index_author_tl,~\seq_use:Nn \l_ale_index_item_seq { ~---~ }
 }


\ExplSyntaxOff

\makeindex

\begin{document}
\lipsum[1]

\index{Author!Work1!1,15} 
\index{Author!Work1!9,32}
\index{Author!Work2!2,24} 
\index{Author!Work2!5,11}
\index{Author!Work1!11,42}

\index{Author2!2,45} 
\index{Author2!4,34}
\index{Author2!6,12} 
\index{Author2!9,4}
\index{Author3}

\newpage
text
\index{Author3}

\printindex
\end{document}

文件.ind将更加结构化,并根据结构分为以下几种情况:无子项、一级子项、两级子项。

在此处输入图片描述

相关内容