答案1
这是对我之前写的两段不同代码的重用(这让我想起了用它制作一个包的计划 ;-))
(看 将 \listoffigures 和 \listoftables 重新定义为表格和汇编文章集的章节样式(旧代码的扩展版本)
我定义了一个\authortableofcontents
命令并重新定义了\chapter
“稍微”以拥有一个额外的可选参数(参见代码中的用法)和一些键值来配置 Author ToC 中条目的外观。
作者 ToC 本身就是一个longtable
,使 pakebreaks 更容易。我选择了 longtable 来提供长垂直规则。
\documentclass{book}
\usepackage{xcolor}
\usepackage{xkeyval}
\usepackage{xparse}
\usepackage{longtable}
\usepackage{array}
\newcolumntype{R}[1]{>{\raggedleft\arraybackslash}p{#1}}
\makeatletter
\let\latex@chapter\chapter
\def\latex@starttoc#1{%
\begingroup
\makeatletter
\begin{longtable}{@{}R{\@pnumwidth}|p{0.8\linewidth}@{}}
\@input{\jobname.#1}%
\end{longtable}
\if@filesw
\expandafter\newwrite\csname tf@#1\endcsname
\immediate\openout \csname tf@#1\endcsname \jobname.#1\relax
\fi
\@nobreakfalse
\endgroup
}
\newcommand{\NoNameAuthor}{Unknown}
\newcommand{\authortocname}{List of Authors}
\newcommand{\AuthorTocSectionDefaultOrder}{subtitle,author,date,journal,url} % Default sections
\NewDocumentCommand{\DeclareArticleSection}{m}{%
\define@key{authortoc}{#1}{%
\expandafter\def\csname kvauthortoc#1\endcsname{##1}
}%
\define@key{authortoc}{#1style}{%
\expandafter\def\csname kvauthortoc#1style\endcsname{##1}
}%
}
\define@key{authortoc}{order}[]{%
\def\KVAuthorTocOrder{#1}%
}
\DeclareArticleSection{title}
\DeclareArticleSection{author}
\DeclareArticleSection{pagenumber}
%\DeclareArticleSection{date}
\def\@makechapterhead#1{%
\vspace*{50\p@}%
{\parindent \z@ \raggedright \normalfont
\ifnum \c@secnumdepth >\m@ne
\if@mainmatter
\huge\bfseries \@chapapp\space \thechapter
\par\nobreak
\vskip 20\p@
\fi
\fi
\interlinepenalty\@M
\Huge \bfseries #1\par\nobreak
\vskip 20\p@
}
}
\NewDocumentCommand{\AddAuthorName}{mmm}{%
\addtocontents{autoc}{\authortoctext{#1}{#2}{#3}}%
}
\newcommand{\authortableofcontents}{%
\chapter*{\authortocname
\@mkboth{%
\MakeUppercase\contentsname}{\MakeUppercase\contentsname}}%
\latex@starttoc{autoc}%
}
\DeclareRobustCommand\authortoctext[3]{%
#3 & #1 \\ & #2 \\[1ex]
}
\RenewDocumentCommand{\chapter}{somO{}}{%
\begingroup
\setkeys{authortoc}{author={\NoNameAuthor},#4}%
\IfBooleanTF{#1}{%
\latex@chapter*{#3}%
}{%
\IfValueTF{#2}{%
\latex@chapter[#2]{#3}
\AddAuthorName{\kvauthortoctitlestyle{#2}}{\kvauthortocauthorstyle{\kvauthortocauthor}}{\kvauthortocpagenumberstyle{\thepage}}%
}{%
\latex@chapter[#3]{#3}
\AddAuthorName{\kvauthortoctitlestyle{#3}}{\kvauthortocauthorstyle{\kvauthortocauthor}}{\kvauthortocpagenumberstyle{\thepage}}%
}%
}%
\endgroup
}
\makeatother
\newcommand{\DefaultAuthorStyle}[1]{%
{\normalsize \itshape #1}
}
\newcommand{\DefaultPagenumberStyle}[1]{%
{\bfseries \color{blue} #1}
}
\newcommand{\DefaultTitleStyle}[1]{%
{\bfseries #1}
}
\presetkeys{authortoc}{authorstyle=\DefaultAuthorStyle,
titlestyle={\DefaultTitleStyle},
pagenumberstyle=\DefaultPagenumberStyle}{}
\begin{document}
\authortableofcontents
\tableofcontents
\chapter{The Fellowship of the Ring}[author={J. R. R. Tolkien}]
\chapter{The Two Towers}[author={J.R.R. Tolkien}, authorstyle={\color{red}}]
\chapter{The Return of the King}[author={J.R.R. Tolkien}, pagenumberstyle={\bfseries \color{brown}}]
\chapter[High Castle]{The man in the high castle}[author={J. P. Dick}, pagenumberstyle={\bfseries \color{brown}}]
\end{document}