![如何使用 tocloft 在同一行获取多个 ToC 条目?](https://linux22.com/image/258515/%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8%20tocloft%20%E5%9C%A8%E5%90%8C%E4%B8%80%E8%A1%8C%E8%8E%B7%E5%8F%96%E5%A4%9A%E4%B8%AA%20ToC%20%E6%9D%A1%E7%9B%AE%EF%BC%9F.png)
这个问题几乎是上一个问题的重复:如何在同一行中获取多个 ToC 条目?。但是,我需要使用 tocloft 而不是 titletoc 来回答,因为在我看来,tocloft 的自定义功能比 titletoc 的更好。您认为使用 tocloft 可行吗?
编辑:这是我想要得到的,书籍类别中的子部分在同一行,没有编号但有页码:
答案1
这是一个可能的解决方案,使用this answer
到如何使用 tocloft 模拟 titletoc:
\documentclass{book}
\usepackage{etoolbox}
\newlength\rightmargintoc
\setlength\rightmargintoc{\linewidth}
\addtolength\rightmargintoc{-3em}
\makeatletter
\def\subsubsectocline#1#2#3#4#5{%
\parshape 2 0em \rightmargintoc \dimexpr\parindent\relax \rightmargintoc
\@tempdima#3
\ifdim\lastskip=1sp\relax\ \else\par\fi{\small\itshape#4,~p.#5.}\hskip1sp%
}
\renewcommand*\l@subsubsection{\subsubsectocline{2}{0em}{3em}}
\makeatother
\pretocmd{\part}{\addtocontents{toc}{\par}}{}{}
\pretocmd{\chapter}{\addtocontents{toc}{\par}}{}{}
\pretocmd{\section}{\addtocontents{toc}{\par}}{}{}
\pretocmd{\subsection}{\addtocontents{toc}{\par}}{}{}
\AtEndDocument{\addtocontents{toc}{\par}}
\begin{document}
\addtocontents{toc}{\setcounter{secnumdepth}{2}}
\tableofcontents
\part{Test Part One}
\chapter{Test Chapter}
\section{Test Section One}
\subsection{Test Subsection One One}
\subsubsection{First Test Subsubsection}
\subsubsection{Second Test Subsubsection}
\subsubsection{Third Test Subsubsection}
\newpage
\subsubsection{Fourth Test Subsubsection}
\subsection{Test Subsection One Two}
\subsubsection{First Test Subsubsection}
\subsubsection{Second Test Subsubsection}
\subsubsection{Third Test Subsubsection}
\part{Test Part One}
\chapter{Test Chapter}
\section{Test Section One}
\end{document}
最终的目录如下: