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}
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}
pointlessnumbers
. See the warning message in thelog
file for the correct option.