[Tex/LaTex] How to create a table of authorship

I am trying to create a table of authorship for a report. I want it to look like a table of contents, only with the names of the authors instead of page numbers. I haven't had any luck looking online. Can anyone give me some advice?

EDIT

Here's what I have so far:

\begin{center}
\rowcolors{1}{white}{light-gray}

\begin{tabular}{l r}
Table of Authorship \\ \hline
Section & Author \\
\hline
Introduction & Author \\
\hline
\hspace{1cm} Motivation & Author \\
\hline
\hspace{1cm} Background & Author \\
\hline
\end{tabular}
\end{center}


But as you guys can see, this is very brittle. If any section changes, the table will need to be updated. It would also be great if the numbers of the sections could be included as well.

EDIT 2

Second attempt at MWE:

\documentclass[a4paper]{article}

\usepackage[table]{xcolor}
\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage[colorinlistoftodos]{todonotes}
\usepackage[margin=0.5in]{geometry}
\usepackage{titlesec}
\graphicspath{ {figures/} }

\setcounter{secnumdepth}{4}

\definecolor{light-gray}{gray}{0.95}

\titleformat{\paragraph}
{\normalfont\normalsize\bfseries}{\theparagraph}{1em}{}
\titlespacing*{\paragraph}
{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}

\title{My MWE}
\author{Robocop}

\begin{document}
\maketitle
\pagebreak
\thispagestyle{empty}

\begin{center}
\rowcolors{1}{white}{light-gray}

\begin{tabular}{l r}
Table of Authorship \\ \hline
Section & Author \\
\hline
Introduction & Author \\
\hline
\hspace{1cm} Motivation & Author \\
\hline
\hspace{1cm} Background & Author \\
\hline
\end{tabular}
\end{center}

\end{document}


See the new version below, with some improvements/explanations

This is a first trial, but has some deficiencies.

• Requires deletion of the .atl file if changes have been made
• Does not provide for \subsection etc. so far.

Now, what's working?

I redefined the \section command to use additional [] argument holding the author name. If empty, the argument value is empty too. In this redefined \section command entries are written to an external file \jobname.atl (atl stands for authorship table list)

To prevent \tableofcontents writting into .atl too, I patched \tableofcontents to use the normal \section command.

The \firsthead should be replaced by \endhead...

\documentclass[a4paper]{article}

\usepackage[table]{xcolor}
\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{longtable}
\usepackage{xpatch}
\usepackage{blindtext}
\usepackage[colorinlistoftodos]{todonotes}
\usepackage[margin=0.5in]{geometry}

\usepackage{xparse}

\let\LaTeXStandardSection\section

\newwrite\authorfile

\AtBeginDocument{%
\IfFileExists{\jobname.atl}{}{%
\immediate\openout\authorfile=\jobname.atl%
\immediate\write\authorfile{%
\string\rowcolors{1}{white}{light-gray}%
\string\begin{longtable}{rp{0.7\linewidth}l}%
\string& & \unexpanded{\bfseries} Author \tabularnewline%
\string\hline^^J%
}%
}%
}

\NewDocumentCommand{\listofauthorships}{}{%
\IfFileExists{\jobname.atl}{%
\LaTeXStandardSection*{TABLE OF AUTHORSHIP}
\begin{center}
\bfseries
\input{\jobname.atl}
\end{center}
}{}%
}

\AtEndDocument{%
\immediate\write\authorfile{%  Close the table
\string\end{longtable}%
}%
\immediate\closeout\authorfile% Close the file
}%

\usepackage{titlesec}

\NewDocumentCommand{\WriteATLSectionLine}{smm}
{%
\IfBooleanTF{#1}{\thesection
\immediate\write\authorfile{%
\string \multicolumn{2}{l}{#2}  & #3\tabularnewline^^J%
\string\hline%
}%
}{%
\immediate\write\authorfile{%
\thesection \string & #2 & #3\tabularnewline^^J%
\string\hline%
}%
}%
}

\xpatchcmd{\tableofcontents}{\section*}{\LaTeXStandardSection*}{}{}

\RenewDocumentCommand{\section}{somO{}}{%
\IfBooleanTF{#1}{% Test for \section*
\LaTeXStandardSection*{#3}%
\WriteATLSectionLine*{#3}{#4}%
}{%
\IfValueTF{#2}{%
\LaTeXStandardSection[#2]{#3}%
\WriteATLSectionLine{#2}{#4}%
}{%
\LaTeXStandardSection{#3}%
\WriteATLSectionLine{#3}{#4}%
}%
}%
}

\graphicspath{ {figures/} }

\setcounter{secnumdepth}{4}

\definecolor{light-gray}{gray}{0.8}

\titleformat{\paragraph}
{\normalfont\normalsize\bfseries}{\theparagraph}{1em}{}
\titlespacing*{\paragraph}
{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}

\title{My MWE}
\author{Robocop}

\begin{document}
\tableofcontents
\maketitle
\pagebreak
\thispagestyle{empty}

\listofauthorships
\clearpage
\section*{Abstract}[All of us]
\section{First}[Gandalf]

\blindtext

\section{Second}[Groucho]

\blindtext
\section{Motivation}[Zeppo]

\blindtext

\section[Conclusions]{Conclusions -- finally}[Harpo]

\begin{center}
\rowcolors{1}{white}{light-gray}

\begin{longtable}{l r}
Table of Authorship \\ \hline
Section & Author \\
\hline
Introduction & Author \\
\hline
\hspace{1cm} Motivation & Author \\
\hline
\hspace{1cm} Background & Author \\
\hline
\end{longtable}
\end{center}

\end{document}


Improved version

• Remove \jobname.atl after changes to the \section... names
• Compile thrice (for correct content and correct width and settings for longtable content)

\documentclass[a4paper]{article}

\usepackage[table]{xcolor}
\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{longtable}
\usepackage{xpatch}
\usepackage{blindtext}
\usepackage{array}
\usepackage[colorinlistoftodos]{todonotes}
\usepackage[margin=0.5in]{geometry}

\usepackage{titlesec}
\usepackage{xparse}

\newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}}  % For quickly changing the column type if needed

\let\LaTeXStandardSection\section
\let\LaTeXStandardSubSection\subsection
\let\LaTeXStandardSubSubSection\subsubsection

\newwrite\authorfile%   File handle to write to

\newcommand{\AuthorHeaderName}{\Large Author} % Header name of the table (on the right of the table )

\newlength{\authorcellwidth}
\setlength{\authorcellwidth}{0.15\textwidth}  % Space for the author name

\newlength{\contentcellwidth}
\setlength{\contentcellwidth}{0.7\textwidth}  % Space for the section names in the table

\AtBeginDocument{%
\IfFileExists{\jobname.atl}{}{%
\immediate\openout\authorfile=\jobname.atl%
\immediate\write\authorfile{%
\string\rowcolors{1}{white}{light-gray}%
\string\begin{longtable}{r@{}l@{}l@{}L{\contentcellwidth}L{\authorcellwidth}}%
\string& & & & \unexpanded{\bfseries \AuthorHeaderName} \tabularnewline%
\string\hline^^J%
}%
}%
}

\newcommand{\listofauthorshipsname}{TABLE OF AUTHORSHIP}

% Command for getting the content of the .atl file
\NewDocumentCommand{\listofauthorships}{}{%
\IfFileExists{\jobname.atl}{%
\LaTeXStandardSection*{\listofauthorshipsname}%
\begin{center}%
\bfseries%
\input{\jobname.atl}%
\end{center}%
}{}%
}

\AtEndDocument{%
\immediate\write\authorfile{%  Close the table
\string\end{longtable}%
}%
\immediate\closeout\authorfile% Close the file
}%

\NewDocumentCommand{\WriteATLSectionLine}{smm}
{%
\IfBooleanTF{#1}{\thesection
\immediate\write\authorfile{%
\string \multicolumn{4}{l@{}}{#2}  & #3\tabularnewline^^J%
\string\hline%
}%
}{%
\immediate\write\authorfile{%
\string\multicolumn{1}{r@{}}{\thesection} \string& \string\multicolumn{3}{l}{#2} & #3\tabularnewline^^J%
\string\hline%
}%
}%
}

\NewDocumentCommand{\WriteATLSubSectionLine}{smm}
{%
\IfBooleanTF{#1}{\thesection
\immediate\write\authorfile{%
\string & \string \multicolumn{3}{l@{}}{#2}  & #3\tabularnewline^^J%
\string\hline%
}%
}{%
\immediate\write\authorfile{%
& \string\multicolumn{1}{r@{}}{\thesubsection} \string& \string\multicolumn{2}{l}{#2} & #3\tabularnewline^^J%
\string\hline%
}%
}%
}

\NewDocumentCommand{\WriteATLSubSubSectionLine}{smm}
{%
\IfBooleanTF{#1}{\thesection
\immediate\write\authorfile{%
\string & & \string \multicolumn{2}{l@{}}{#2}  & #3\tabularnewline^^J%
\string\hline%
}%
}{%
\immediate\write\authorfile{%
& & \string\multicolumn{1}{r@{}}{\thesubsubsection} \string& \string\multicolumn{1}{l}{#2} & #3\tabularnewline^^J%
\string\hline%
}%
}%
}

%% 'Guaranteeing' the usage of traditional \section stuff, not the redefined ones!
\xpatchcmd{\tableofcontents}{\section*}{\LaTeXStandardSection*}{}{}
\xpatchcmd{\listoffigures}{\section*}{\LaTeXStandardSection*}{}{}
\xpatchcmd{\listoftables}{\section*}{\LaTeXStandardSection*}{}{}

\RenewDocumentCommand{\section}{somO{}}{%
\IfBooleanTF{#1}{% Test for \section*
\LaTeXStandardSection*{#3}%
\WriteATLSectionLine*{#3}{#4}%
}{%
\IfValueTF{#2}{%
\LaTeXStandardSection[#2]{#3}%
\WriteATLSectionLine{#2}{#4}%
}{%
\LaTeXStandardSection{#3}%
\WriteATLSectionLine{#3}{#4}%
}%
}%
}

\RenewDocumentCommand{\subsection}{somO{}}{%
\IfBooleanTF{#1}{% Test for \section*
\LaTeXStandardSubSection*{#3}%
\WriteATLSubSectionLine*{#3}{#4}%
}{%
\IfValueTF{#2}{%
\LaTeXStandardSubSection[#2]{#3}%
\WriteATLSubSectionLine{#2}{#4}%
}{%
\LaTeXStandardSubSection{#3}%
\WriteATLSubSectionLine{#3}{#4}%
}%
}%
}

\RenewDocumentCommand{\subsubsection}{somO{}}{%
\IfBooleanTF{#1}{% Test for \section*
\LaTeXStandardSubSubSection*{#3}%
\WriteATLSubSubSectionLine*{#3}{#4}%
}{%
\IfValueTF{#2}{%
\LaTeXStandardSubSubSection[#2]{#3}%
\WriteATLSubSubSectionLine{#2}{#4}%
}{%
\LaTeXStandardSubSubSection{#3}%
\WriteATLSubSubSectionLine{#3}{#4}%
}%
}%
}

% Other stuff by the OP

\graphicspath{ {figures/} }

\setcounter{secnumdepth}{4}

\definecolor{light-gray}{gray}{0.8}

\titleformat{\paragraph}
{\normalfont\normalsize\bfseries}{\theparagraph}{1em}{}
\titlespacing*{\paragraph}
{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}

\title{My MWE}
\author{Robocop}

\begin{document}
\tableofcontents
\maketitle
\pagebreak
\thispagestyle{empty}

\listofauthorships
\clearpage
\section*{Abstract}[All of us]
\section{First}[Gummo]

\blindtext

\section{Second}[Groucho]
\subsection{First Subsection}[Chico]
\subsubsection{First SubSubsection}[Groucho]
\subsubsection*{Second SubSubsection}[The 6th Marx Brother]

\blindtext
\section{Motivation}[Zeppo]
\subsection*{Demotivation}[Gummo]

\blindtext

\section[Conclusions]{Conclusions -- finally}[Harpo]

\end{document}


Explanations:

• \let\LaTeXStandardSection\section grabs the original definition of \section and stores it to \LaTeXStandardSection -- this way a redefinition by \RenewDocumentCommand{\section} can use the old behaviour of \section (which is needed here anyway) and add extra facilities to it. The same is true for \subsection and \subsubsection.
• The command argument list of \section is now {somO{}}, meaning **s**starred ...**o**ptional ... **m**andatory ... **O**ptional, i.e. the starred version of\section, then \section[toc-entry]{longer title} and later on the new optional argument for the author name, initially set to be empty (i.e. O{}).

• \RenewDocumentCommand{\section}...checks if it's a starred section\section*, using\WriteATLSectionLine*{#3}{#4}with or\WriteATLSectionLine{#3}{#4}, which takes care whether the section number should be displayed or not.

• Code in \AtBeginDocument is executed before \begin{document}starts, so this can be used to open the output file for the entries. This is done via\immediate\openout\authorfile=\jobname.atl. In addition, some starter code for the beginning for the longtableis written to the file already, as well the end code stuff in\AtEndDocument, in which the the file is closed.
• \immediate\write\authorfile{% } is used to write stuff to the file, direct commands must be prepended with \string, whereas\thesection must be expanded right there, otherwise it would use the last section value of the document, not the relevant one.

This is the content of the \jobname.atl

\rowcolors{1}{white}{light-gray}
\begin{longtable}{r@{}l@{}l@{}L{\contentcellwidth }L{\authorcellwidth }}
& & & & \bfseries \AuthorHeaderName  \tabularnewline
\hline

\multicolumn{4}{l@{}}{Abstract} & All of us\tabularnewline
\hline
\multicolumn{1}{r@{}}{1} & \multicolumn{3}{l}{First} & Gummo\tabularnewline
\hline
\multicolumn{1}{r@{}}{2} & \multicolumn{3}{l}{Second} & Groucho\tabularnewline
\hline
& \multicolumn{1}{r@{}}{2.1} & \multicolumn{2}{l}{First Subsection} & Chico\tabularnewline
\hline
& & \multicolumn{1}{r@{}}{2.1.1} & \multicolumn{1}{l}{First SubSubsection} & Groucho\tabularnewline
\hline
& & \multicolumn{2}{l@{}}{Second SubSubsection} & The 6th Marx Brother\tabularnewline
\hline
\multicolumn{1}{r@{}}{3} & \multicolumn{3}{l}{Motivation} & Zeppo\tabularnewline
\hline
& \multicolumn{3}{l@{}}{Demotivation} & Gummo\tabularnewline
\hline
\multicolumn{1}{r@{}}{4} & \multicolumn{3}{l}{Conclusions} & Harpo\tabularnewline
\hline
\end{longtable}