4

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?

Sample: http://www.wpi.edu/Pubs/E-project/Available/E-project-042612-131146/unrestricted/12_oryx_mqp_paper.pdf

Thanks in advance!

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}

Authorship Table

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}
  • 2
    Welcome to TeX SE! We are going to need a minimal working example (MWE) to be of much help. Lots of stuff about your current code will affect the answer. – cfr Apr 9 '15 at 1:15
  • Thank you for your welcome! I made an edit to my question with the code I have so far. – RoboCop87 Apr 9 '15 at 1:21
  • 1
    We need a document we can copy-paste-compile to see what you see. For example, the document class you are using is important. So are any packages you are loading which might affect the handling of this. Also, how are you specifying the authors at the relevant points in the document? Any more automatic solution is going to have to hook into the commands you are using for that, which in turn depend on the class and any packages which further customise those commands. – cfr Apr 9 '15 at 1:34
  • Sorry, I tried again. I hope this helps! – RoboCop87 Apr 9 '15 at 1:40
  • 1
    @RoboCop87: Have a look on my possible solution – user31729 Apr 9 '15 at 9:22
3

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

enter image description here

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

enter image description here

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 
\endhead
\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}
  • This looks great, im still picking through it to understand how it works, but the output is just what I want. How hard will it be to extend this to subsection and subsubsection? – RoboCop87 Apr 9 '15 at 16:16
  • @RoboCop87: Well, basically it's just copying the section code and replacing section with sub(sub)section ;-) I'll do my best ;-) – user31729 Apr 9 '15 at 17:17
  • If its that straight forward don't worry about it, I'm sure I can figure it out. Thanks again for your help! – RoboCop87 Apr 9 '15 at 17:27
  • @RoboCop87: Well, it's a little bit cumbersome actually, but I've got some better solution right now, but not really configurable – user31729 Apr 9 '15 at 18:02
  • That would be great, im still struggling to learn what these commands mean, what they do, and what I need to change. Googles been helping but its a lot to take in in a single day XD I shouldn't need configurable, just functional – RoboCop87 Apr 9 '15 at 18:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.