[Tex/LaTex] Authblk for chapters? – Author and affiliations per chapter

authblkauthorchapterstable of contents

I'm trying to compile an scrbook and what I would like is to shon an author with affiliation for each chapter. The authblk package allows us to do this for the title.

Is there anyway to adapt it to chapters? I've tried different things, but most didn't work out. Does anyone maybe have a working piece of tex?

This is how I imagine it to work
(this is no working example, just an illustration:

\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}

This should end up like this and additionally showing the author names and additionally a list of affiliations like this:
enter image description here

In the TOC I would just like to show a comma separated list of authors.

I've added the bounty b/c my tries just failed.

Best Answer

No package (apart hyperref), simple minded. Needs to be customized probably.

Note: a solution without extra mark-up with affils environment is possible, but this one is easier to customize via enumitem for example for the list of affiliations.

edit

I have added variant using \sffamily, suppressing indentation of first paragraph following list of affiliations and controlling vertical space using enumitem for it.


\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}

TOC:

enter image description here

CHAPTERS:

enter image description here

enter image description here


Updated code

\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}

Produces

enter image description here

enter image description here