没有章节的目录

没有章节的目录

我正在编写一本摘要小册子,每篇摘要都有标题。我没有使用\section这些标题的命令,但现在我需要将它们放在目录中。例如,我有:

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

我的问题是:有没有办法告诉 LaTeX 将这些标题视为章节?或者我需要将它们全部标记为章节?如果是这样,我该如何编辑章节的格式,使它们具有上述格式?

谢谢你!

答案1

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

添加:精炼版本,列出作者和标题,还允许为目录指定备用标题(如分段命令一样)。它使用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}

输出如下:

第二个代码示例的输出

答案2

你可以通过titlesec和 来实现这一点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} 

在此处输入图片描述 在此处输入图片描述

相关内容