[Tex/LaTex] Name a section in Latex TOC (add subtitle to contentsline)

sectioningtable of contents

I have my Latex document (documentclass is article) which consists of several \sections and \subsections.

The \tableofcontents command generates my TOC as I want (in this case: hyperreffed, with page number, with dots etc.), but for the sections, I would like to add a "section subtitle".

As an example: my current TOC looks like

1 Layout
    1.1 Main Window
    1.2 Footer
2 Navigation
    2.1 Basic structure
    2.2 Overview page

Now I want to add a subtitle to every section, which I expected to work like \section{Layout}{this section describes the layout}, which appearently doesn't work.

What I want:

1 Layout - this section describes the layout
    1.1 Main Window
    1.2 Footer
2 Navigation - here you will get information on foobar
    2.1 Basic structure
    2.2 Overview page

Best Answer

If the "subtitle" attributes are to be the same from those of the title, and you want the information to appear right after the title, you can use the optional argument of the sectional units:

\documentclass{article}

\begin{document}

\tableofcontents

\section[Layout -- This section describes the layout]{Layout}
\subsection{Main Window}
\subsection{Footer}
\section[Navigation -- Here you will get information on foobar]{Navigation}
\subsection{Basic structure}
\subsection{Overview page}

\end{document}

enter image description here

As tohecz mentions in a comment this will also add this subtitle to the header marks.

Another sometimes used format is to write this "subtitle" right below the title for the sectional unit. The following code shows one way to achieve this; the idea is to define a new command \sectionsubtitle which writes the information to the ToC, immitating the way section entries are typeset, but suppressing the sectional and page numbering, and the leading dots; additionally, with this approach the subtitles won't be added to the head marks:

\documentclass{article}
\usepackage{etoolbox}

\makeatletter
\let\@nodottedtocline\@dottedtocline
\patchcmd{\@nodottedtocline}{\hbox{.}}{\hbox{}}{}{}
\patchcmd{\@nodottedtocline}{\normalcolor #5}{\normalcolor}{}{}
\newcommand*\l@sectionsubtitle{\@nodottedtocline{1}{0em}{1.5em}}
\makeatother

\def\sectionsubtitle#1{%
    \addcontentsline{toc}{sectionsubtitle}{\protect\numberline{}#1}%
}

\begin{document}

\tableofcontents

\section{Layout}
\sectionsubtitle{This section describes the layout}
\subsection{Main Window}
\subsection{Footer}
\section{Navigation}
\sectionsubtitle{Here you will get information on foobar}
\subsection{Basic structure}
\subsection{Overview page}

\end{document}

enter image description here