Latex 两个带有手动设置目录的标题页

Latex 两个带有手动设置目录的标题页

我需要制作一个包含标题、摘要和手动设置的目录的标题页(我正在合并多个现有 pdf)。要手动设置目录,我使用此解决方案:手动创建目录(而不是自动生成)?这是我的代码:

\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}

我输出的第一页完全符合预期。但还有第二页,其中包含标题、空白摘要,没有目录。我需要代码仅生成第一页。这是 \maketitle 或 \tableofcontents 的误用还是其他原因?

另外:该脚本仅在运行一次后生成目录(并且已生成.toc 文件。有没有办法让它在第一次运行时生成目录?

答案1

欢迎!您的命令\toccontents不存在于您正在加载的包中。您可能需要用\maketitle替换\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}

相关内容