5

I am compiling a booklet of abstracts, each of which has its title. I didn't treat use the command \section for these titles, but now I need to put them in a table of contents. For example I have:

\documentclass[12pt]{book}

\begin{document}

\tableofcontents
\cleardoublepage


\begin{center}
\textsc{Bla bla} \\
 Author
\end{center}

 This is an abstract.

 \newpage 

 \begin{center}
 \textsc{Bla bla 2} \\
  Author 2
 \end{center}

 This is another abstract. 

 \newpage


 and so on.

 \end{document}

My question is: is there a way to tell LaTeX to treat these titles as if they were sections? or would I need to label them all as sections? If so, how can I edit the format of sections so that they have the format above?

Thank you!

  • Do they have to be numbered? – Bernard Aug 19 '16 at 22:31
  • not necessarily... – RobertP. Aug 19 '16 at 22:37
  • What should appear in the table of contents, exactly? – Bernard Aug 19 '16 at 22:41
  • It would awesome to have both the title (e.g., "Bla bla") and possibly the Author in the toc... – RobertP. Aug 19 '16 at 22:48
7

Use \addcontentsline:

% My standard header for TeX.SX answers:
\documentclass[a4paper]{article} % To avoid confusion, let us explicitly 
                                 % declare the paper format.

\usepackage[T1]{fontenc}         % Not always necessary, but recommended.
% End of standard header.  What follows pertains to the problem at hand.

\newenvironment*{TOCabstract}[2]{%
    \begin{center}
        \textsc{#1}%
        \addcontentsline{toc}{section}{#1}\par\nobreak
        #2\par
        \nobreak\smallskip
}{\end{center}}



\begin{document}

\tableofcontents

\begin{TOCabstract}{The first title}{Arthur Uther Thor}
    Abstract one.
\end{TOCabstract}

\begin{TOCabstract}{The second title}{Brutus Cyclops Dull}
    Abstract two.
\end{TOCabstract}

\end{document}

Addition: A refined version, that lists the authors along with the titles, and also allows an alternative title to be specified for the ToC (as the sectioning commands do). It uses xparse:

% My standard header for TeX.SX answers:
\documentclass[a4paper]{article} % To avoid confusion, let us explicitly 
                                 % declare the paper format.

\usepackage[T1]{fontenc}         % Not always necessary, but recommended.
% End of standard header.  What follows pertains to the problem at hand.

\usepackage{xparse}

\NewDocumentEnvironment{TOCabstract}{ o m m }{%
    \center
        \textsc{#2}%
        \IfValueTF{#1}{%
            \addcontentsline{toc}{section}{#1, by #3}%
        }{%
            \addcontentsline{toc}{section}{#2, by #3}%
        }%
        \par\nobreak
        #3%
        \par\nobreak\smallskip
}{\endcenter}



\begin{document}

\tableofcontents

\begin{TOCabstract}{The first title}{Arthur Uther Thor}
    Abstract one.
\end{TOCabstract}

\begin{TOCabstract}{The second title}{Brutus Cyclops Dull}
    Abstract two.
\end{TOCabstract}

\begin{TOCabstract}[Shorter 3rd title]{The third title, long version}
            {Jonathan Horatio Quick}
    Abstract three.
\end{TOCabstract}

\end{document}

Here is the output:

Output of the second code sample

  • that's GREAT! Grazie! :) – RobertP. Aug 19 '16 at 23:14
  • @RobertP.: Just a minute, I’ve made a silly mistake (#2 in place of #3). – GuM Aug 19 '16 at 23:18
  • Yeah, I was about to tell you about that. Thank you – RobertP. Aug 19 '16 at 23:21
  • Wait - let me clarify what I need. Here's what I need each title to be like: Title 1 (in small caps) \\ Author - Affiliation (in italics) What I would like to put in the table of contents is Title 1 and Author. – RobertP. Aug 19 '16 at 23:25
  • @RobertP.: Please go on: try to implement that yourself. :-) I’ve put you on the way, try to continue on your own: that’s the way we all have learnt to write LaTeX code—and anything else, too! :-) Feel free to ask for hints, I’ll stay at my computer for some time… :-) – GuM Aug 19 '16 at 23:31
2

You can have this, with titlesec and titletoc:

\documentclass[12pt]{book}
\usepackage[showframe]{geometry}
 \usepackage[clearempty, explicit]{titlesec} %
\newcommand\Author[1]{\\ \normalfont#1}
\newcommand{\sectionbreak}{\clearpage}
\titleformat{name = \section, numberless}[block]{\scshape}{}{0pt}{\begin{center}#1\end{center}}[\addcontentsline{toc}{section}{#1}]
\usepackage{titletoc}
\titlecontents{section}
     [0em] % i
     {\medskip}
     {\thecontentslabel\enspace}%\thecontentslabel
     {\scshape}
     {\titlerule*[1pc]{.}\contentspage}%]

\pagestyle{plain}
\begin{document}

\tableofcontents
\cleardoublepage

\section*{Bla bla 1 Bla bla 1\Author{Author1}}
 This is an abstract.

\section*{Bla bla 2 \Author{Author 2}}
 This is another abstract.

 and so on.

 \end{document} 

enter image description here enter image description here

  • if i would like to add the affiliation too, would it be something like: \newcommand\Affiliation[1]{--- \itshape#1} to be added before the \Author command? – RobertP. Aug 20 '16 at 1:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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