Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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
share|improve this question
    
one way to accomplish this is to suppress the automatically created section entry and replace it. this was addressed in my answer to this question, although the reason for doing so was different. however, it shouldn't be too difficult to adapt that answer to do what you want. –  barbara beeton May 15 '12 at 13:00

1 Answer 1

up vote 8 down vote accepted

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

share|improve this answer
    
Remark: Tis will add the comments to header marks as well. –  yo' May 15 '12 at 19:06
    
@tohecz: only the first solution; the second one won't. I'll add a little note. –  Gonzalo Medina May 15 '12 at 20:17
    
Yep, thanks! What you posted as first code example was exactly what I was looking for! –  Dennis May 16 '12 at 8:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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