我觉得我应该能够解决这个问题,但是在几个月的时间里花了几个小时反复研究之后,我还是不知所措。本质上我想做以下事情:
\documentclass{article}
\usepackage{imakeidx}
\newcommand{\bday}[3]{\index{#1!#2!#3}}
\makeindex
\begin{document}
\section{Birthday people}
Ted's birthday is March 20.\bday{March}{20}{Ted}\\
Bob's birthday is March 20.\bday{March}{20}{Bob}\\
Ann's birthday is April 30.\bday{April}{30}{Alice}\\
\printindex
\end{document}
然而索引的输出看起来像这样,它们按标题(月份,按日历顺序而不是字母顺序)排序并按日期组合,并且没有页码:
有没有合理直接的方法来做到这一点?谢谢。
答案1
以下是一些可以帮助您入门的内容:
我过去常常xstring
指定月份的排序顺序。如果需要,可以编写一个不使用这个包的 case 语句。
为了将项目合并为一行,使用分号作为分隔符并消除页码,我重新定义了\subsubitem
。
\def\subsubitem#1,#2{#1;}
消除页码的不太复杂的方法如下从索引条目中删除页码,但目前我无法让它工作。我知道我以前用过这个解决方案,所以不确定为什么它现在不起作用。
代码:
\documentclass{article}
\usepackage{imakeidx}
\usepackage{xstring}
\def\subsubitem#1,#2{#1;}% Combine into one line
\newcommand{\bday}[3]{%
\IfStrEqCase{#1}{%
{January}{\index{01@#1!#2!#3}}%
{Feburary}{\index{02@#1!#2!#3}}%
{March}{\index{03@#1!#2!#3}}%
{April}{\index{04@#1!#2!#3}}%
{March}{\index{05@#1!#2!#3}}%
{June}{\index{06@#1!#2!#3}}%
{July}{\index{07@#1!#2!#3}}%
{August}{\index{08@#1!#2!#3}}%
{September}{\index{09@#1!#2!#3}}%
{October}{\index{10@#1!#2!#3}}%
{November}{\index{11@#1!#2!#3}}%
{December}{\index{12@#1!#2!#3}}%
}%
}
\makeindex
\begin{document}
\section{Birthday people}
Ted's birthday is March 20.\bday{March}{20}{Ted}
Bob's birthday is March 20.\bday{March}{20}{Bob}
Ann's birthday is April 30.\bday{April}{30}{Alice}
\printindex
\end{document}
答案2
感谢上面的@Peter,我终于可以开始工作了。我放弃了在索引中包含月份的尝试,而是直接构建了 12 个单独的索引。虽然不是很优雅,但更容易格式化和控制。基本上是以下代码,然后格式化索引标题的章节或节标题。
\documentclass{article}
\usepackage{imakeidx}
\def\subitem#1,#2{\, #1;}% Combine into one line
\newcommand{\bday}[3]{\index[#1]{#2!#3}}
\makeindex[name=January,title=January,columns=1]
\makeindex[name=February,title=February,columns=1]
\makeindex[name=March,title=March,columns=1]
\makeindex[name=April,title=April,columns=1]
\makeindex[name=May,title=May,columns=1]
\makeindex[name=June,title=June,columns=1]
\makeindex[name=July,title=July,columns=1]
\makeindex[name=August,title=August,columns=1]
\makeindex[name=September,title=September,columns=1]
\makeindex[name=October,title=October,columns=1]
\makeindex[name=November,title=November,columns=1]
\makeindex[name=December,title=December,columns=1]
\begin{document}
\section{Birthday people}
Ted's birthday is March 20.\bday{March}{20}{Ted}
Bob's birthday is March 20.\bday{March}{20}{Bob}
Ann's birthday is April 30.\bday{April}{30}{Alice}
\printindex[January]
\printindex[February]
\printindex[March]
\printindex[April]
\printindex[May]
\printindex[June]
\printindex[July]
\printindex[August]
\printindex[September]
\printindex[October]
\printindex[November]
\printindex[December]
\end{document}