我正在审查一系列文件并创建了一份如下报告:
\chapter{Interesting Things}
\input{thing1.tex}
\input{thing2.tex}
\input{thing3.tex}
其中thing*.tex
每个看起来像:
\section{The Name of The Thing}
\subsection{Summary}
A summary
\subsection{Details}
This contains details about the thing
\subsection{Conclusions}
My final analysis of the thing.
但是,我发现列表中的某些东西很相似,我想将它们分组在一起。我并不关心它们是如何编号的,但我希望分组出现在目录中以组织它们。例如,我的一些东西是圆形的,有些是方形的,所以我想创建一个新的级别或分组,如下所示:
\chapter{Interesting Things}
\grouping{Square Things}
\input{thing1.tex}
\input{thing2.tex}
\grouping{Circle Things}
\input{thing3.tex}
我想避免更改所有单个文件。这可能吗?
答案1
您可能可以根据自己的需要使事情变得尽可能复杂,但从简单性的角度来看,让它\grouping{<something>}
以与 ToC 条目非常相似的方式运行似乎就足够了\chapter*{<something>}
:
\documentclass{book}
% \grouping{<something>} acts similar to a ToC entry for \chapter*{<something>}
\newcommand{\grouping}[1]{\addcontentsline{toc}{chapter}{\protect\numberline{}#1}}
\begin{document}
\tableofcontents
\chapter{Interesting Things}
\grouping{Square Things}
\section{The Name of The Thing}
\subsection{Summary}
A summary
\subsection{Details}
This contains details about the thing
\subsection{Conclusions}
My final analysis of the thing.
\section{The Name of The Thing}
\subsection{Summary}
A summary
\subsection{Details}
This contains details about the thing
\subsection{Conclusions}
My final analysis of the thing.
\grouping{Circle Things}
\section{The Name of The Thing}
\subsection{Summary}
A summary
\subsection{Details}
This contains details about the thing
\subsection{Conclusions}
My final analysis of the thing.
\end{document}
答案2
这是一个具有额外缩进和分组的解决方案:
使用\groupthings[some vertical spacing]{Foo}
将 写入chapter like group header
到ToC
。
这会自动将假章节标题和章节条目移动指定的量(tocloft
这里用于简化这一点。)
在新的实际章节开始后,必须恢复旧的缩进,在使用\RestoreIndents
新的缩进时会自动调用。\chapter
\documentclass{book}
\usepackage{tocloft}
\newlength{\extrachapindent}
\newlength{\extrasecindent}
\setlength{\extrachapindent}{10pt} % Indentation of chapters
\setlength{\extrasecindent}{20pt} % Indentation of sections
% Store the old values
\newlength{\origchapindent}
\newlength{\origsecindent}
\setlength{\origchapindent}{\cftchapindent}
\setlength{\origsecindent}{\cftsecindent}
\newcommand{\RestoreIndents}{% Switch back to old values
\addtocontents{toc}{\protect\setlength{\cftchapindent}{\origchapindent}}%
\addtocontents{toc}{\protect\setlength{\cftsecindent}{\origsecindent}}%
}
\usepackage{xpatch}
\xpretocmd{\chapter}{\RestoreIndents}{}{} % Automatically call \RestoreIndents before a new chapter is used
\newcommand{\groupthings}[2][2pt]{%
\addtocontents{toc}{\protect\addvspace{#1}}% Vertical spacing
\addtocontents{toc}{\protect\setlength{\cftchapindent}{\extrachapindent}}% indent the chapters
\addtocontents{toc}{\protect\contentsline{chapter}{#2}{}}% Write the text
\addtocontents{toc}{\protect\addvspace{#1}}% Other vertical spacing
\addtocontents{toc}{\protect\setlength{\cftsecindent}{\extrasecindent}}% Indent the chapters
}
\begin{document}
\tableofcontents
\chapter{Some things}
\groupthings{Rectangular thingies}
\section{Rectangle things}
\section{Square things}
\groupthings{Round thingies}
\section{Circular things}
\subsection{Foo}
\subsubsection{Foobar}
\section{Oval things}
\RestoreIndents % Explicitly restore
\section{Something not being grouped}
\chapter{Other things}
\section{Triangular shapes}
\end{document}