4

I’m working on a group project in which we have to indicate the name of the person who worked on a certain topic. I’d like to insert the authors’ names to the toc one line after the respective section’s title. I used the following code so far:

\documentclass[a4paper, 12pt, pointlessnumbers]{scrreprt}

\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}

\newcommand\autsection[2]{%
  \section[#1\newline{\normalfont\small\itshape#2}]{#1}}

\begin{document}
\tableofcontents
\chapter{Title}
\autsection{Title}{Author}

\end{document}

The problem is, that I’d like to have the default section line setting (title + dotted line + page number) and just add a name on the next line. Using my code, it looks like this so far: enter image description here

1
  • Off-topic: Don't use deprecated option pointlessnumbers. See the warning message in the log file for the correct option.
    – cabohah
    Commented Aug 4 at 16:16

2 Answers 2

3

I would define a new TOC entry type author and use it:

\documentclass[12pt,numbers=noenddot]{scrreprt}

\usepackage[ngerman]{babel}

\DeclareTOCStyleEntry[%
  level=\sectiontocdepth,% same level as for section entries
  indent:=subsection,% same indent as for subsection
  numwidth:=subsection,
  linefill=\hfill,% don't print dots
  pagenumberbox=\ignorebox,% don't print page number
  onstartsamelevel=\nopagebreak,% prevent page breaks between section and author entry
  entryformat=\small\textit
]{tocline}{author}
\newcommand*{\ignorebox}[1]{}

\newcommand\autsection[2]{%
  \section{#1}%
  \addtocentrydefault{author}{}{#2}%
}

\begin{document}
\tableofcontents
\chapter{Title}
\autsection{Title}{Author}

\end{document}

1.1 Title\Author

With this solutions you can use all the options of TOC entry style tocline to configure the author entry. See the KOMA-Script manual for more information.

Note: I've also replaced the deprecated option pointlessnumbers and also removed the not needed option a4paper.

Note: Instead of using indent:=subsection and numwidth:=subsection you can also use indent:=section and numwidth:=section in combination with class option toc=numberline:

\documentclass[12pt,numbers=noenddot,toc=numberline]{scrreprt}

\usepackage[ngerman]{babel}

\DeclareTOCStyleEntry[%
  level=\sectiontocdepth,% same level as for section entries
  indent:=section,% same indent as for section
  numwidth:=section,% same number width as for section
  linefill=\hfill,% don't print dots
  pagenumberbox=\ignorebox,% don't print page number
  onstartsamelevel=\nopagebreak,% prevent page breaks between section and author entry
  entryformat=\small\textit
]{tocline}{author}
\newcommand*{\ignorebox}[1]{}

\newcommand\autsection[2]{%
  \section{#1}%
  \addtocentrydefault{author}{}{#2}%
}

\begin{document}
\tableofcontents
\chapter{Title}
\autsection{Title}{Author}

\end{document}

The result would be the same, but independent from subsection entries.

Candy

As an extension, you can also add a new option author to the \section command. To do so, you need to activate the extended option handling using, e.g., KOMA-Script option headings=optiontotocandhead and define a new family key for section entries using \FamilyStringKey[.section]{KOMAarg}{<optionname>}{<storagemacro>}. Then you can extend command \addsectiontocentry by code to add the author entry to the ToC. I would also recommend to initialize the storage macro with every new \section to also support sections without author:

\documentclass[12pt,numbers=noenddot,headings=optiontoheadandtoc]{scrreprt}

\usepackage[ngerman]{babel}

\DeclareTOCStyleEntry[%
  level=\sectiontocdepth,
  indent:=subsection,
  numwidth:=subsection,
  linefill=\hfill,
  pagenumberbox=\ignorebox,
  onstartsamelevel=\nopagebreak,
  entryformat=\small\textit
]{tocline}{author}
\newcommand*{\ignorebox}[1]{}

\FamilyStringKey[.section]{KOMAarg}{author}{\sectionauthor}% new section
                                % command option
\makeatletter
\AddToHook{cmd/section/before}{\let\sectionauthor\@empty}% initialize \sectionautor
\AddToHook{cmd/addsectiontocentry/after}{% after section entry to ToC
  \ifx\sectionauthor\@empty\else
    \addtocentrydefault{author}{}{\sectionauthor}% add author entry
  \fi
}
\makeatother

\begin{document}
\tableofcontents
\chapter{Title}
\section[author=Author's name]{Section with author}
\section{Section without author}

\end{document}

1.1 Section with author\Author's name + 1.1 Section without author

3

You have two simple choices here. \addcontentsline which will place the text at the desired indentaion but will add the page number, or \addtocontents where you will have to guess or calculate the indentation needed.

\documentclass[a4paper, 12pt, pointlessnumbers]{scrreprt}

\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}

\begin{document}
\tableofcontents
\chapter{Title}
\section{Title}
\addcontentsline{toc}{section}{\string\numberline{ }Author}
\addtocontents{toc}{\string\hspace{3.8em}Author\par}

Some text here.

\end{document}

demo

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .