我正在尝试编写一个scrbook
,我希望为每个章节列出作者及其所属关系。该authblk
软件包允许我们对标题执行此操作。
有没有办法将它改编成章节?我尝试过不同的方法,但大多数都没有成功。有人可能有一份可用的 tex 吗?
这就是我想象它的工作方式(这不是一个工作示例,只是一个例证:
\documentclass{scrbook}
\begin{document}
\title{My Book}
\author{F. D. C. Willard}
\chapter{Chapter 1}
\chapterauthor[1]{Don Joe}
\chapterauthor[1]{F. D. C. Willard}
\chapteraffil[1]{TeX Stackexchange School}
\chapter{Chapter 2}
\chapterauthor[1]{John Doe}
\chapterauthor[1]{Jane Doe}
\chapterauthor[2]{Albert Einstein}
\chapterauthor[3]{Pepe Frog}
\chapterauthor[3]{Willy Wonka}
\chapteraffil[1]{Harvard University}
\chapteraffil[2]{Tex School}
\chapteraffil[3]{High School 4C District}
\end{document}
这应该是这样的,另外还显示作者姓名以及附属机构列表,如下所示:
在目录中,我只想显示以逗号分隔的作者列表。
我添加了赏金,因为我的尝试失败了。
答案1
没有软件包(hyperref 除外),思路简单。可能需要定制。
注意:可以使用不带额外环境标记的解决方案affils
,但是这个解决方案更容易通过enumitem
例如从属关系列表进行定制。
编辑
我添加了使用的变体\sffamily
,抑制了从属关系列表后第一段的缩进,并使用控制了垂直空间enumitem
。
\documentclass{scrbook}
\usepackage{hyperref}
\newif\ifnewauthor
\newauthortrue
\newcounter{affils}
\makeatletter
\def\chapterauthor[#1]#2{\ifnewauthor\else, \fi
#2\textsuperscript{\hyperref[authaffil\the\value{chapter}.#1]{#1}}%
\ifnewauthor\newauthorfalse\gdef\chapterauthors{#2}\else
\g@addto@macro\chapterauthors{, #2}\fi
\ignorespaces % to remove end of line spaces from
% \chapterauthor[foo]{bar} input lines
}
\makeatother
\def\chapteraffil[#1]{\item[#1 --]%
\refstepcounter{affils}%
\label{authaffil\the\value{chapter}.#1}%
}
\newenvironment{affils}
{\addtocontents{toc}{\chapterauthors\string\par}\begin{enumerate}}
{\end{enumerate}\global\newauthortrue}
\begin{document}
\title{My Book}
\author{F. D. C. Willard}
\maketitle
\tableofcontents
\chapter{Chapter 1}
\chapterauthor[1]{Don Joe}
\chapterauthor[1]{F. D. C. Willard}
\begin{affils}
\chapteraffil[1]{TeX Stackexchange School}
\end{affils}
\chapter{Chapter 2}
\chapterauthor[1]{John Doe}
\chapterauthor[1]{Jane Doe}
\chapterauthor[2]{Albert Einstein}
\chapterauthor[3]{Pepe Frog}
\chapterauthor[3]{Willy Wonka}
\begin{affils}
\chapteraffil[1]{Harvard University}
\chapteraffil[2]{Tex School}
\chapteraffil[3]{High School 4C District}
\end{affils}
\end{document}
目录:
章节:
更新代码
\documentclass{scrbook}
\usepackage{enumitem, hyperref}
\newif\ifnewauthor
\newauthortrue
\newcounter{affils}
\makeatletter
\def\chapterauthor[#1]#2{\ifnewauthor\sffamily\else, \fi
#2\textsuperscript{\hyperref[authaffil\the\value{chapter}.#1]{#1}}%
\ifnewauthor\newauthorfalse\gdef\chapterauthors{#2}\else
\g@addto@macro\chapterauthors{, #2}\fi
\ignorespaces % to remove end of line spaces from
% \chapterauthor[foo]{bar} input lines
}
\makeatother
\def\chapteraffil[#1]{\item[#1 --]%
\refstepcounter{affils}%
\label{authaffil\the\value{chapter}.#1}%
}
\makeatletter
\newenvironment{affils}
{\addtocontents{toc}{\chapterauthors\string\par}%
\begin{itemize}[itemsep=0pt, parsep=0pt]}
{\end{itemize}\par
\global\newauthortrue
\@nobreaktrue
\aftergroup\normalfont}
\makeatother
\begin{document}
\title{My Book}
\author{F. D. C. Willard}
\maketitle
\tableofcontents
\chapter{Chapter 1}
\chapterauthor[1]{Don Joe}
\chapterauthor[1]{F. D. C. Willard}
\begin{affils}
\chapteraffil[1]{TeX Stackexchange School}
\end{affils}
No indentation for this first text paragraph.
\chapter{Chapter 2}
\chapterauthor[1]{John Doe}
\chapterauthor[1]{Jane Doe}
\chapterauthor[2]{Albert Einstein}
\chapterauthor[3]{Pepe Frog}
\chapterauthor[3]{Willy Wonka}
\begin{affils}
\chapteraffil[1]{Harvard University}
\chapteraffil[2]{Tex School}
\chapteraffil[3]{High School 4C District}
\end{affils}
And this text is with ``normal font'' settings.
\end{document}
生产
答案2
对于那些需要它的人,这里有一个修改,允许按作者管理多个隶属关系
它使用tikz
允许使用该\foreach
命令的包。
\documentclass{report}
\usepackage{hyperref}
\usepackage{tikz}
\newif\ifnewauthor
\newauthortrue
\newcounter{affils}
\makeatletter
\def\chapterauthor[#1]#2{\ifnewauthor\else, \fi
#2\foreach \x [count=\xi] in {#1}{%
\ifnum\xi=1 \textsuperscript{\hyperref[authaffil\the\value{chapter}.\x]{\x}}%
\else \textsuperscript{\hyperref[authaffil\the\value{chapter}.\x]{,\x}}%
\fi%
}%
\ifnewauthor\newauthorfalse\gdef\chapterauthors{#2}\else%
\g@addto@macro\chapterauthors{, #2}\fi%
\ignorespaces % to remove end of line spaces from \chapterauthor[foo]{bar} input lines
}
\makeatother
\def\chapteraffil[#1]{\item[#1 --]%
\refstepcounter{affils}%
\label{authaffil\the\value{chapter}.#1}%
}
\newenvironment{affils}
{\addtocontents{toc}{\chapterauthors\string\par}\begin{enumerate}}
{\end{enumerate}\global\newauthortrue}
\begin{document}
\title{My Book}
\author{F. D. C. Willard}
\maketitle
\tableofcontents
\chapter{Chapter 1}
\chapterauthor[1,2]{John Doe}
\chapterauthor[1,3]{Jane Doe}
\chapterauthor[2,3]{Albert Einstein}
\begin{affils}
\chapteraffil[1]{Harvard University}
\chapteraffil[2]{Tex School}
\chapteraffil[3]{High School 4C District}
\end{affils}
\end{document}