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 been creating a latex template for an abstract book of our workshop. I have defined new commands such as titleoftalk, speaker, speakeaddress, email, ...

\newcommand{\titleoftalk}[1]{\begin{center}{\large \bf #1}\\\end{center}} 
\newcommand{\speaker}[1]{\begin{center}{\large #1}\end{center}}
\newcommand{\speakeraddress}[1]{\vspace{-0.75cm}\begin{center}{\it #1}\\ \vspace{1cm} ABSTRACT \end{center}}
\newcommand{\email}[1]{\textit{email:} \url{#1}}

and wrote my abstracts for each speaker using these new commands. I need a help to write \addtocontents{toc} command.

Suppose we have 2 abstracts:

\speaker{Speaker 1}
\titleoftalk{Title 1}
%abstract of the first speaker is here
\speaker{Speaker 2}
\titleoftalk{Title 2}
%abstract of the second speaker is here

I want to recreate the toc page as

Title of Talks
1. Speaker 1   Title 1   ................................... the page number   
2. Speaker 2   Title 2   ................................... the page number

Where and how should I write my \addtocontents{toc} command?

share|improve this question
    
Sorry to bother you, but I noticed that you haven't accepted answers to your questions (nice questions, by the way!). I know that you have up-voted answers, but accepting them is a different action; in case of doubt please see How do you accept an answer?. –  Gonzalo Medina Sep 13 '12 at 14:59
    
I updated my answer with another option. –  Gonzalo Medina Sep 13 '12 at 22:24
add comment

1 Answer

Here's one possibility:

\documentclass{article}
\usepackage{lipsum}

\newcounter{speaker}

\newcommand{\speaker}[1]{%
  \stepcounter{speaker}%
  \csname phantomsection\endcsname
  \begin{center}{\large #1}\end{center}
  \addcontentsline{toc}{section}{\numberline{\thespeaker.}#1}
}

\newcommand{\titleoftalk}[1]{%
  \begin{center}{\large\bfseries #1}\end{center}
  \addcontentsline{toc}{subsection}{#1}
}

\makeatletter
\renewcommand*\l@section[2]{%
  \ifnum \c@tocdepth >\z@
    \addpenalty\@secpenalty
    \addvspace{1.0em \@plus\p@}%
    \setlength\@tempdima{1.8em}%
    \begingroup
      \parindent \z@ \rightskip \@pnumwidth
      \parfillskip -\@pnumwidth
      \leavevmode \bfseries
      \advance\leftskip\@tempdima
      \hskip -\leftskip
      #1\nobreak\hfil \nobreak\par%\hb@xt@\@pnumwidth{\hss #2}\par
    \endgroup
  \fi}
\renewcommand*\l@subsection{\@dottedtocline{2}{1.8em}{2.3em}}
\makeatother

\renewcommand\contentsname{Title of Talks}
\begin{document}

\tableofcontents
\newpage
\speaker{Name of Speaker A}
\titleoftalk{This is the title of the talk by speaker one}
\lipsum[1-10]
\speaker{Name of Speaker B}
\titleoftalk{This is the title of the talk by speaker two}
\lipsum[1-10]
\speaker{Name of Speaker C}
\titleoftalk{This is the title of the talk by speaker three}
\lipsum[1-10]
\speaker{Name of Speaker D}
\titleoftalk{This is the title of the talk by speaker four}
\lipsum[1-10]
\speaker{Name of Speaker E}
\titleoftalk{This is the title of the talk by speaker five}
\lipsum[1-10]

\end{document}

enter image description here

The idea is to use the standard \tableofcontents command and \addcontensline inside \speaker and \titleoftalk so that the inclusion in the modified ToC will be automatic. Each speaker name will be formatted as a section and the corresponding title, as a subsection (using slightly modified versions of the default \l@section and \l@subsection). Provision was made so that if hyperref is used, anchors will be added in the appropriate locations to have functional hyperlinks.

Here's a variation putting the speaker name and the tile in the same line:

\documentclass{article}
\usepackage{lipsum}

\newcounter{speaker}

\newcommand{\speaker}[1]{%
  \gdef\currspeaker{#1}
  \stepcounter{speaker}%
  \csname phantomsection\endcsname
  \begin{center}{\large #1}\end{center}
}
\newcommand{\titleoftalk}[1]{%
  \begin{center}{\large\bfseries #1}\end{center}
  \addcontentsline{toc}{section}{\numberline{\thespeaker.}\currspeaker~--~{\itshape#1}}
}

\makeatletter
\renewcommand*\l@section[2]{%
  \ifnum \c@tocdepth >\z@
    \addpenalty\@secpenalty
    \addvspace{1.0em \@plus\p@}%
    \setlength\@tempdima{1.8em}%
    \begingroup
      \parindent \z@ \rightskip \@pnumwidth
      \parfillskip -\@pnumwidth
      \leavevmode %\bfseries
      \advance\leftskip\@tempdima
      \hskip -\leftskip
      #1\nobreak\leaders\hbox{$\m@th\mkern \@dotsep mu\hbox{.}\mkern \@dotsep
mu$}\hfill\nobreak\hb@xt@\@pnumwidth{\hss #2}\par
    \endgroup
  \fi}
\renewcommand*\l@subsection{\@dottedtocline{2}{1.8em}{2.3em}}
\makeatother

\renewcommand\contentsname{Title of Talks}
\begin{document}

\tableofcontents
\newpage
\speaker{Name of Speaker A}
\titleoftalk{This is the title of the talk by speaker one spanning more than one line for the example}
\lipsum[1-10]
\speaker{Name of Speaker B}
\titleoftalk{This is the title of the talk by speaker two}
\lipsum[1-10]
\speaker{Name of Speaker C}
\titleoftalk{This is the title of the talk by speaker three spanning more than one line for the example}
\lipsum[1-10]
\speaker{Name of Speaker D}
\titleoftalk{This is the title of the talk by speaker four}
\lipsum[1-10]
\speaker{Name of Speaker E}
\titleoftalk{This is the title of the talk by speaker five spanning more than one line for the example}
\lipsum[1-10]

\end{document}

enter image description here

In case one cannot (ab)use the standard \tableofcontents (because, for example, it has to be used for its intending purpose), one can easily modify the above examples and produce a \listoftalks command with the help of \@starttoc; here's an example showing this approach with the formatting used in the second example code above:

\documentclass{article}
\usepackage{lipsum}

\newcounter{speaker}

\newcommand{\speaker}[1]{%
  \gdef\currspeaker{#1}
  \stepcounter{speaker}%
  \csname phantomsection\endcsname
  \begin{center}{\large #1}\end{center}
}
\newcommand{\titleoftalk}[1]{%
  \begin{center}{\large\bfseries #1}\end{center}
  \addcontentsline{tot}{speaker}{\numberline{\thespeaker.}\currspeaker~--~{\itshape#1}}
}

\makeatletter
\newcommand\listtalksname{Title of Talks}
\newcommand\listoftalks{\section*{\listtalksname}\@starttoc{tot}}
\newcommand*\l@speaker[2]{%
  \ifnum \c@tocdepth >\z@
    \addpenalty\@secpenalty
    \addvspace{1.0em \@plus\p@}%
    \setlength\@tempdima{1.8em}%
    \begingroup
      \parindent \z@ \rightskip \@pnumwidth
      \parfillskip -\@pnumwidth
      \leavevmode %\bfseries
      \advance\leftskip\@tempdima
      \hskip -\leftskip
      #1\nobreak\leaders\hbox{$\m@th\mkern \@dotsep mu\hbox{.}\mkern \@dotsep
mu$}\hfill\nobreak\hb@xt@\@pnumwidth{\hss #2}\par
    \endgroup
  \fi}
\makeatother

\begin{document}

\listoftalks
\newpage
\speaker{Name of Speaker A}
\titleoftalk{This is the title of the talk by speaker one spanning more than one line for the example}
\lipsum[1-10]
\speaker{Name of Speaker B}
\titleoftalk{This is the title of the talk by speaker two}
\lipsum[1-10]
\speaker{Name of Speaker C}
\titleoftalk{This is the title of the talk by speaker three spanning more than one line for the example}
\lipsum[1-10]
\speaker{Name of Speaker D}
\titleoftalk{This is the title of the talk by speaker four}
\lipsum[1-10]
\speaker{Name of Speaker E}
\titleoftalk{This is the title of the talk by speaker five spanning more than one line for the example}
\lipsum[1-10]

\end{document}

enter image description here

share|improve this answer
add comment

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.