[Tex/LaTex] Include \maketitle in table of contents to compile “book” of IEEE articles

ieeetrantable of contents

Background:

I am creating a compilation of multiple IEEE format articles. This compilation will have a single table of contents. Each paper includes a title and \maketitle command. I would like the TOC to include the title of each paper as the primary level, along with all the sections/subsections etc.

    \documentclass[journal]{IEEEtran}

    \begin{document}
    \onecolumn
    \tableofcontents
     \twocolumn        


    % Title and Author information  Paper 1
        \title{Title 1}
        \author{Author 1}
        % Make the title area
        \maketitle
       $ Paper Content

    % Title and Author information  Paper 2
        \title{Title 2}
        \author{Author 2}
        % Make the title area
        \maketitle
       $ Paper Content

\end{document}

Should generate a TOC that approximates this:

  1. Title 1

    I – Section 1

    I-A Subsection 1

    I-B Subsection 2

    II – Section 2

  2. Title 2

    I – Section 1

    I-A Subsection 1

    I-B Subsection 2

    II – Section 2

Question:

How can I modify the TOC to include titles?

I am open to other suggestions. I realize that the ieeetran or other article/journal classes do not use \chapter or \part commands, but if there was a way to force this operation while not changing the class, I would be interested in such a solution as well.

Best Answer

\maketitle is a command, which 'disables' itself right before the end of the macro (well, it is \relaxed then). As such, a further call to this macro will provide nothing. By using a patch command, this \let\maketitle\relax can be catched and a \addcontentsline command injected instead, which will do the ToC entry then.

I further introduced a titlecounter counter, which is automatically refstepped, so that \label should also work. The format of the ToC entry is quite simple at the moment -- change at will.

Mico had an important objection: There should be a \clearpage right at the start of the \maketitle command, which will shipout possible floats from the preceeding article. However, I restricted this behaviour to the 2nd etc. \maketitle.

\documentclass[journal]{IEEEtran}

\usepackage{etoolbox}%
\usepackage{xpatch}
\usepackage{blindtext}

\makeatletter
\newcounter{titlecounter}
\xpretocmd{\maketitle}{\ifnumgreater{\value{titlecounter}}{1}}{\clearpage}{}{} % Well, this is lazy at the end ;-)

\xpatchcmd{\maketitle}{\let\maketitle\relax\let\@maketitle\relax}{\refstepcounter{titlecounter}\addcontentsline{toc}{section}{\protect{\numberline{\thetitlecounter}{\@title~ \@author}}}}{\typeout{Patching was successful}}{\typeout{patching failed}}%
\makeatother
\begin{document}
\onecolumn
\tableofcontents
\twocolumn        



% Title and Author information  Paper 1
\title{Title 1}
\author{Author 1}
% Make the title area
\maketitle
\blindtext[10]
%$ Paper Content

% Title and Author information  Paper 2
\title{Title 2}
\author{Author 2}
% Make the title area
\maketitle
\blindtext[20]
%$ Paper Content

\end{document}

enter image description here

Version with level indentation

Use \setlength{\articlesectionindent}{10pt} (or any other appropiate value), in order to get the indentation of levels relative to the title toc entry.

The resetting of sections etc. is done with the command \@addtoreset{section}{titlecounter}, i.e. each time the titlecounter is stepped, the sections are reset (and consecutively the subsections etc. as well)

\documentclass[journal]{IEEEtran}

\usepackage{etoolbox}%
\usepackage{xpatch}
\usepackage{blindtext}
\usepackage{tocloft}%

\newlength{\articlesectionshift}%
\setlength{\articlesectionshift}{10pt}%
\addtolength{\cftsecindent}{\articlesectionshift}%

\makeatletter
\newcounter{titlecounter}
\xpretocmd{\maketitle}{\ifnumgreater{\value{titlecounter}}{1}}{\clearpage}{}{} % Well, this is lazy at the end ;-)
\xpatchcmd{\maketitle}{\let\maketitle\relax\let\@maketitle\relax}{\refstepcounter{titlecounter}\begingroup
  \addtocontents{toc}{\begingroup\addtolength{\cftsecindent}{-\articlesectionshift}}%
  \addcontentsline{toc}{section}{\protect{\numberline{\thetitlecounter}{\@title~ \@author}}}%
  \addtocontents{toc}{\endgroup}}{\typeout{Patching was successful}}{\typeout{patching failed}}%

\@addtoreset{section}{titlecounter}

\makeatother
\begin{document}
\onecolumn
\tableofcontents
\twocolumn        



% Title and Author information  Paper 1
\title{Title 1}
\author{Author 1}
% Make the title area
\maketitle

\section{First}
\subsection{First subsection of 1st section}%
\subsection{2nd subsection of 1st section}%
\subsection{3rd subsection of 1st section}%
\subsection{4th subsection of 1st section}%

\blindtext[10]
\section{Two}
\subsection{First subsection of 2nd section}%

% Title and Author information  Paper 2
\title{Title 2}
\author{Author 2}
% Make the title area
\maketitle
\section{First from second paper}
\subsection{First subsection of 2nd section of 2nd article}%

\blindtext[20]

%$ Paper Content

\end{document}

enter image description here

** Warning ** Both versions will fail in conjunction with hyperref package. It's some issue with the \footnotemark command.