1

I am the author of one section of a report. I want to but my name right under the caption of this section. And I want this to appear in the table of contents.

This Question gives a very nice answer to this question, if I wanted to but my name under a chapter's caption. However, it is not the chapter that I am writing, but only this one section. For some reason the code provided in the mentioned question doesn't work for sections, and I don't understand LaTeX very well, such that I could change it. Maybe someone can help?

Here is the code that I have copied and tried out:

\documentclass{article}
\usepackage{suffix}

  \newcommand{\printsectionauthor}[1]{%
      {\parindent0pt\vspace*{-25pt}%
      \linespread{1.1}\large\scshape#1%
      \par\nobreak\vspace*{35pt}}
      \@afterheading%
    }
    \newcommand{\authortoc}[1]{%
      \addtocontents{toc}{\vskip-10pt}%
      \addtocontents{toc}{%
        \protect\contentsline{section}%
        {\hskip1.3em\mdseries\scshape\protect\scriptsize#1}{}{}}
      \addtocontents{toc}{\vskip5pt}%
    }

\title{Title of the Report}
\author{My Name}

\maketitlepage
\cleardoublepage
\addcontentsline{toc}{chapter}{\listfigurename}
\listoffigures

\begin{document}
\chapter{First Chapter of the Report}
\Section{My Section}\label{mySection}
\printsectionauthor{My Name}
\Subsection{First Subsection}
\end{document}
3
  • 2
    Instead of posting code fragments, can you please put the fragments into a compilable document that that people can play with.
    – Alan Munn
    Aug 4 '18 at 17:23
  • 1
    (1) welcome, (2) please always post a full minimal example of how your code is used. In many cases the document class you are using greatly affect the chosen solution. As for adding to the toc in a section related form (per the second macro) give one guess as to how you'd change thst from being chapter related to being section related.
    – daleif
    Aug 4 '18 at 17:24
  • 1
    ok. I have tried to create this example. As on how I would change it? To me the command only seems to handle vertical spaces and similar, meaning where to put the name. I don't see how it is specific to chapters.
    – Luk
    Aug 4 '18 at 17:41
1

article class does not provide \chapter, \Section and \Subsection. So I will use report class with \chapter, \section and \subsection.

You could load package tocbasic and declare a new ToC entry for the sectionauthor.

\documentclass{report}
\usepackage{tocbasic}

\makeatletter
\DeclareTOCStyleEntry[
  level=1,
  indent=3.8em,
  numwidth=0pt,
  entryformat=\normalfont\scshape\scriptsize,
  pagenumberformat=\@gobble,
  linefill=\hfill,
  onstartsamelevel=\relax
]{tocline}{sectionauthor}

\newcommand{\printsectionauthor}[1]{%
  {\parindent0pt\vspace*{-10pt}%
  \large\scshape#1%
  \addcontentsline{toc}{sectionauthor}{#1}%
  \par\nobreak\vspace*{10pt}
  }%
  \@afterheading%
}
\makeatother

\begin{document}
\tableofcontents
\chapter{First Chapter of the Report}
\section{My Section}\label{mySection}
\printsectionauthor{My Name}
\subsection{First Subsection}
\end{document}

enter image description here

enter image description here

1
  • thank you so much! It is working! ...now I only need to understand what is actually going on, hahaha
    – Luk
    Aug 4 '18 at 20:10
1

Your code produces a large amount of errors and I am not sure what the purpose of various parts is. So I just followed your link, copied the definition of \chapterauthor to \sectionauthor and made marginal changes.

\documentclass[12pt]{book}
\usepackage{lipsum}

\makeatletter
\newcommand{\chapterauthor}[1]{%
  {\parindent0pt\vspace*{-25pt}%
  \linespread{1.1}\large\scshape#1%
  \par\nobreak\vspace*{35pt}}
  \@afterheading%
}
\newcommand{\sectionauthor}[1]{%
  {\parindent0pt\vspace*{-15pt}%
  \linespread{1.1}\large\scshape#1%
  \par\nobreak\vspace*{15pt}}
  \@afterheading%
}

\makeatother

\begin{document}

\chapter{This is a test}
\chapterauthor{S.~Subham Soni}

\section{The content of this section is not valid on Tuesdays
}
\sectionauthor{M.~Murmeltier}
\lipsum[4]

\end{document} 

enter image description here

1

Here is an entirely different approach. Since we want the TOC dotted line to connect to the title and not the author, the author is horizontally overlapped with the title, only on the next line. It is treated like a very large descender. Note: this only works for a one line title.

\documentclass{report}
\usepackage{suffix}

\title{Title of the Report}
\author{My Name}

\begin{document}
\titlepage
\tableofcontents
%\cleardoublepage
%\addcontentsline{toc}{chapter}{\listfigurename}
%\listoffigures% not relevant

\chapter{First Chapter of the Report}
\section{\rlap{\normalsize\raisebox{-\baselineskip}{My Name}}My Section}\label{mySection}
\subsection{First Subsection}
\end{document}

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.