[Tex/LaTex] Add author before chapter title in ToC

table of contents

I working on an edition with various author. And I want the chapter's author name being shown in the ToC. I have modified the chapter to add the author there and use it in the page header as follows:

\documentclass[10pt,twoside]{memoir}
\usepackage[german]{babel}
\usepackage{blindtext}
\usepackage[ansinew]{inputenc} 
\usepackage{scrpage2}

%%
% Kopf- und Fußzeile
%%
\usepackage{fancyhdr}
\pagestyle{fancy}

\makeatletter

%%
% Kapitelüberschrift um Feld für Autor erweitern
%%
\newcommand*{\orgichapter}{}
\let\orgichapter\chapter
\renewcommand*{\chapter}[1]{%
  \gdef\chapterauthor{#1}% 
  \orgichapter
}
\renewcommand*{\chapterformat}{}

%%
% Kapitelüberschrift formatieren
%%
\renewcommand{\printchaptername}{} % Kapitelnamen unterdrücken
\renewcommand{\chapternamenum}{}
\renewcommand{\printchapternum}{}  % Kapitelnummer unterdrücken
\renewcommand{\afterchapternum}{}

%%
% Autor nach Titel einfügen
%%
\renewcommand{\afterchaptertitle}{%
\vskip\onelineskip\begin{large}\textit{\chapterauthor}\end{large}
\vskip\onelineskip}

%%
% Zählung auf der Ebene \section beginnen
%%
\renewcommand{\thesection}{\arabic{section}}
\setcounter{secnumdepth}{3} % Subsection mit Zähler (1.1) versehen

%%
% Kolumnentitel
%%
\renewcommand{\chaptermark}[1]{ \markboth{#1}{}  } % Stil der Kopfzeile zurücksetzen
\renewcommand{\sectionmark}[1]{ \markright{#1}{} } % Stil der Kopfzeile zurücksetzen
\fancyhf{}                        % Use fancyhdr
\fancyhead[CE]{\small\chapterauthor}    % L for Left, E for Even page
\fancyhead[CO]{\small\leftmark}         % Aufsatztitel als Kolumentitel
%\fancyhead[CO]{\rightmark}       % \chapter als Kolumnentitel
\fancyhead[LE]{\thepage}          % L for Left, E for Even page
\fancyhead[RO]{\thepage} 
\renewcommand{\headrulewidth}{0pt} % Keine Trennlinie

%%
% Inhaltsverzeichnis
%%
\renewcommand*{\cftchapterdotsep}{\cftdotsep}
\settocdepth{chapter}
\renewcommand{\cftchapterfont}{\normalfont}
\renewcommand{\cftchapterpagefont}{\normalfont}

%%
% Dokumentenbeginn
%%
\begin{document}
\tableofcontents* 

\chapter{Walter von der Vogelweide}[]{Ich saß uf eynem Steine?}
\section{Und dachte Bein mit Beine}

\Blindtext

\clearpage

\chapter{Hartman von Aue}[Was auch immer]{So gebt nur mehr und immer mehr}

\section{Moralische Quellen der Irrationalität}
\thispagestyle{empty}
\Blindtext
\section{Das ist nur Blindtext}
\Blindtext
\end{document}

How can I use the \chapterauthor now in ToC? It should look like this:

Walter von der Vogelweide
Title of the chapter  ........  123

Hartmann von Aue
Title of the chapter  ........  345

I know, many have asked that before, but I can't get it working anyhow.

Best Answer

I would suggest you not to overload the standard commands. In the following example I defined a command \authortoc to be used before each \chapter; this commands includes its argument in the table of contents (I chose italicized font, but you can easily change this) and also makes provision for the marks to be used in the headers.

I also used \makepagestyle and its family of associated commands to define the page style (memoir has its own mechanism to define page styles so it's not necessary (nor advisable) to use fancyhdr):

\documentclass[10pt,twoside]{memoir}
\usepackage[german]{babel}
\usepackage{blindtext}
\usepackage[ansinew]{inputenc} 

\renewcommand{\thesection}{\arabic{section}}
\setcounter{secnumdepth}{3} % Subsection mit Zähler (1.1) versehen

%%
% Kolumnentitel
%%
\renewcommand{\chaptermark}[1]{ \markboth{#1}{}  } % Stil der Kopfzeile zurücksetzen
\renewcommand{\sectionmark}[1]{ \markright{#1}{} } % Stil der Kopfzeile 

% Page style
\makepagestyle{mystyle}
\makeevenhead{mystyle}{\thepage}{\small\chapterauthor}{}
\makeoddhead{mystyle}{}{\slshape\leftmark}{\thepage}
\pagestyle{mystyle}

%%
% Inhaltsverzeichnis
%%
\renewcommand*{\cftchapterdotsep}{\cftdotsep}
\settocdepth{chapter}
\renewcommand{\cftchapterfont}{\normalfont}
\renewcommand{\cftchapterpagefont}{\normalfont}

\makeatletter
\DeclareRobustCommand\authortoctext[1]{%
{\addvspace{10pt}\nopagebreak\leftskip0em\relax
\rightskip \@tocrmarg\relax
\noindent\itshape#1\par\addvspace{-7pt}}}
\makeatother
\newcommand\authortoc[1]{%
  \gdef\chapterauthor{#1}%
  \addtocontents{toc}{\authortoctext{#1}}}

%%
% Dokumentenbeginn
%%
\begin{document}
\tableofcontents* 
\authortoc{Walter von der Vogelweide}
\chapter{Ich sass uf eynem Steine?}
\section{Und dachte Bein mit Beine}
\Blindtext\Blindtext\Blindtext\Blindtext

\authortoc{Hartman von Aue}
\chapter[Was auch immer]{So gebt nur mehr und immer mehr}
\section{Moralische Quellen der Irrationalitat}
\Blindtext\Blindtext\Blindtext\Blindtext
\end{document}

Here's an image of the resulting ToC:

enter image description here

I suppressed code from the original example that was not relevant for the problem mentioned. I also changed the spelling og some German words just for the example (I felt lazy about changing the encoding of my editor),

Related Question