1

I need to make a title page that includes title, abstract, and manually set table of contents (I'm combining multiple existing pdfs). To manually set the TOC I'm using this solution: Manually create a table of contents (instead of automatically generated)? Here's my code:

\documentclass[preprint,12pt]{elsarticle}
\usepackage{graphicx}
\usepackage{amssymb}
\usepackage{lineno}

\usepackage[margin=1in]{geometry}
\pagestyle{empty}

\newcommand{\addsection}[3]{\addtocontents{toc}{\protect\contentsline{section}{\protect\numberline{#1}#2}{#3}}}
\newcommand{\addsubsection}[3]{\addtocontents{toc}{\protect\contentsline{subsection}{\protect\numberline{#1}#2}{#3}}}

\begin{document}
\begin{frontmatter}

\title{This is the Title}
\begin{abstract}
This is the abstract.
\end{abstract}

\addsection{1}{Primary}{1}
\addsubsection{1.1}{Module A}{1}
\addsubsection{1.2}{Module B}{5}
\addsection{2}{Secondary}{10}
\addsubsection{2.1}{Examples}{10}
\addsection{3}{Tertiary}{11}
\addsubsection{3.1}{Test One}{11}
\addsubsection{3.1}{Test Two}{23}
\addsubsection{3.1}{Test Three}{45}

\maketitle
\toccontents

\end{frontmatter}
\end{document}

The first page of my output appears exactly as it should. But there is also a second page that has the title, a blank abstract, and no TOC. I need the code to ONLY generate the first page. Is it misuse of \maketitle or \tableofcontents or something else?

Also: the script only generates the TOC after being run once(and the .toc file has been generated. Is there a way to make it generate the TOC on the first run?

1 Answer 1

2

Welcome! Your command \toccontents does not exist within the packages you are loading. And you might want to replace \maketitle by \titlepage.

\documentclass[preprint,12pt]{elsarticle}
\usepackage{graphicx}
\usepackage{amssymb}
\usepackage{lineno}

\usepackage[margin=1in]{geometry}
\pagestyle{empty}

\newcommand{\addsection}[3]{\addtocontents{toc}{\protect\contentsline{section}{\protect\numberline{#1}#2}{#3}}}
\newcommand{\addsubsection}[3]{\addtocontents{toc}{\protect\contentsline{subsection}{\protect\numberline{#1}#2}{#3}}}

\begin{document}
\begin{frontmatter}

\title{This is the Title}
\begin{abstract}
This is the abstract.
\end{abstract}
\end{frontmatter}

\addsection{1}{Primary}{1}
\addsubsection{1.1}{Module A}{1}
\addsubsection{1.2}{Module B}{5}
\addsection{2}{Secondary}{10}
\addsubsection{2.1}{Examples}{10}
\addsection{3}{Tertiary}{11}
\addsubsection{3.1}{Test One}{11}
\addsubsection{3.1}{Test Two}{23}
\addsubsection{3.1}{Test Three}{45}

\tableofcontents
\titlepage


\end{document}
1
  • How to add a small jump space in each subsection text? Apr 25, 2020 at 1:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .