答案1
以下是一个基本的实现,它吞噬了\section
目录中除标题之外的所有内容,并将其设置在适当的adjustwidth
环境中(具有典型/预期的左/右缩进)。
\documentclass{book}
\usepackage{lipsum}
\usepackage{etoolbox,changepage}
\setcounter{secnumdepth}{0}% Only number up to section level 0 (chapter)
\makeatletter
\renewcommand{\l@section}[2]{#1. }%
\patchcmd{\@chapter}% <cmd>
{\addtocontents}% <search>
{\ifnum\value{chapter}<1\else
\addtocontents{toc}{\begin{adjustwidth}{1.5em}{\@pnumwidth}}%
\fi
\addtocontents}% <replace>
{}{}% <success><failure>
\pretocmd{\chapter}{%
%\addtocontents{toc}{\protect\par}
\ifnum\value{chapter}>0
\addtocontents{toc}{\end{adjustwidth}\par}
\fi
}
{}{}% <success><failure>
\AtEndDocument{\addtocontents{toc}{\end{adjustwidth}}}% Close off final adjustwidth environment
\makeatother
\begin{document}
\tableofcontents
\sloppy
\chapter{First chapter}\lipsum[1-50]
\section{First section}\lipsum[1-50]
\section{Second section}\lipsum[1-50]
\section{Third section}\lipsum[1-50]
\section{Fourth section}\lipsum[1-50]
\section{Fifth section}\lipsum[1-50]
\section{Sixth section}\lipsum[1-50]
\section{Seventh section}\lipsum[1-50]
\section{Last section}\lipsum[1-50]
\chapter{Second chapter}\lipsum[1-50]
\section{First section}\lipsum[1-50]
\section{Second section}\lipsum[1-50]
\section{Third section}\lipsum[1-50]
\section{Last section}\lipsum[1-50]
\chapter{Third chapter}\lipsum[1-50]
\section{First section}\lipsum[1-50]
\section{Second section}\lipsum[1-50]
\section{Third section}\lipsum[1-50]
\section{Last section}\lipsum[1-50]
\chapter{Last chapter}\lipsum[1-50]
\section{First section}\lipsum[1-50]
\section{Second section}\lipsum[1-50]
\section{Third section}\lipsum[1-50]
\section{Last section}\lipsum[1-50]
\end{document}