我想创建一个包含 3 个主要部分的目录:简介、常规部分和实验部分。
部分标题在一般部分和实验部分(例如聚乙烯醇衍生物的合成)是相同的,我希望将页码分为两列,页码取决于标题出现在哪个部分。
这是一个示例的屏幕截图,我希望它能清楚地表明我的目标是什么。
答案1
新更新。将两个不同章节的目录合并在一起的通用方法,这些章节共享一些共同的章节/小节标题。
使用包埃托克。每个章节单元都经过标记,然后,在文档中的任何位置(在 之前\end{document}
或 之前\chapter
,但不在 之前\section
)创建一个虚拟章节,用户在其中插入一行,\dummysection
其中包含两个章节中每个章节的标题,后跟两个标签(或可能只有一个,另一个是一对空括号)。 后跟\dummychapter
一个命令,然后带有参数的\localtableofcontents \label{toc:combined}
命令将打印所需的目录。\CombinedTOC
{toc:combined}{label of the first chapter}{label of the second chapter}
线条的创建\dummysection
也可以在某种程度上实现自动化。
输出:
代码:
\documentclass{book}% used to have chapters
%\usepackage[linktoc=all,breaklinks]{hyperref} % if latex+dvips
\usepackage[linktoc=all]{hyperref} % for testing compatibility
\usepackage{etoc}
% PREPARATION FOR PRODUCING A COMBINED TOC OF TWO CHAPTERS
\etocsetlevel{dummychapter}{6} % invisible in TOCs until level is modified
\etocsetlevel{dummysection}{6} % invisible in TOCs until level is modified
\etocsetlevel{dummysubsection}{6} % invisible in TOCs until level is modified
\etocsetlevel{dummysubsubsection}{6} % invisible in TOCs until level is modified
\newcommand*{\dummychapter}
% THIS WILL ESCAPE THE AUTOMATIC ADDITION TO THE FILE BOOKMARKS BY HYPERREF
{\etoctoccontentsline{dummychapter}{A dummy chapter}}
% after \dummychapter a
% \localtableofcontents will know that its
% top level is "section" (once the level
% of dummychapter as been set to 0=chapter)
\newcommand*{\dummysection}[3]
{\etoctoccontentsline{dummysection}{#1\ExtraRefs{#2}{#3}}}
\newcommand*{\dummysubsection}[3]
{\etoctoccontentsline{dummysubsection}{#1\ExtraRefs{#2}{#3}}}
\newcommand*{\dummysubsubsection}[3]
{\etoctoccontentsline{dummysubsubsection}{#1\ExtraRefs{#2}{#3}}}
% This will be added to the .toc file, but not seen by the
% main \tableofcontents because the dummy* things will be ignored.
\DeclareRobustCommand\ExtraRefs[2]
{\hfill\rlap
{\makebox[2cm]{\makebox[1.5cm]
{\if\relax#1\relax\else\ref{#1}\leaders\hbox to .1cm{\hss.\hss}
\hfill\pageref{#1}\fi}}%
\makebox[2cm]{\makebox[1.5cm]
{\if\relax#2\relax\else\ref{#2}\leaders\hbox to .1cm{\hss.\hss}
\hfill\pageref{#2}\fi}}}}
% #1: label given to the dummy \localtableofcontents after \dummychapter
% #2: label of first concerned chapter, here the General
% #3: label of second concerned chaper, here the Experimental
\newcommand*{\CombinedTOC}[3]{%
\begingroup
\parindent 0pt
\parfillskip 0pt
\leftskip 0cm
\rightskip 4cm
\etocsetstyle {section}
{}
{\leavevmode\leftskip 0pt\relax }
{\bfseries\etocname\par\smallskip}
{}
\etocsetstyle {subsection}
{}
{\leavevmode\leftskip 15pt\relax }
{\mdseries\etocname\par}
{\addvspace{\medskipamount}}
\etocsetstyle {subsubsection}
{}
{\leavevmode\leftskip 30pt\relax }
{\mdseries\etocname\par}
{}
\etocsetlevel{dummychapter}{0}
\etocsetlevel{dummysection}{1}
\etocsetlevel{dummysubsection}{2}
\etocsetlevel{dummysubsubsection}{3}
\etocruledstyle [1]
{\bfseries Combined Contents of chapters \ref{#2} and \ref{#3}}
\renewcommand{\etocaftertitlehook}{\hfill{}\rlap{\makebox[2cm]{\textbf{Gen.}}%
\makebox[2cm]{\textbf{Exp.}}}\par}
\setcounter{tocdepth}{3}
\tableofcontents \ref {#1}
\setcounter{tocdepth}{1}
\endgroup
}
\begin{document}
\setcounter {secnumdepth}{3}
\setcounter {tocdepth}{1}
\tableofcontents
\CombinedTOC {toc:combined}{chap:G}{chap:E}
\chapter{Introduction}
\cleardoublepage
\chapter{Objective}
\cleardoublepage
\chapter{General Part}\label{chap:G}
\section{A section not in the Experimental part}\label{g:0}
\section{State of the Art}\label{g:1}
\subsection{A}\label{g:1.1}
\clearpage
\subsection{B}\label{g:1.2}
\clearpage
\section{Evaluation of Peracrylate 1}\label{g:2}
\subsection{E}\label{g:2.1}
\clearpage
\subsection{F}\label{g:2.2}
\clearpage
\subsection{G}\label{g:2.3}
\clearpage
\subsection{H}\label{g:2.4}
\clearpage
\subsection{Various Methods: a very long subsection name to see what
happens then with the formatting inside the etoc table of
contents}\label{g:2.5}
% no subsubsections in the General part.
\chapter{Experimental Part}\label{chap:E}
\section{Evaluation of Peracrylate 1}\label{e:1}
\subsection{E}\label{e:1.1}
\clearpage
\subsection{F}\label{e:1.2}
\clearpage
\subsection{G}\label{e:1.3}
\clearpage
\subsection{H}\label{e:1.4}
\clearpage
\subsection{Various Methods: a very long subsection name to see what
happens then with the formatting inside the etoc table of
contents}\label{e:1.5}
% these subsubsections are only here
\subsubsection{Method A}\label{e:1.5.1}
\subsubsection{Method B}\label{e:1.5.2}
\section{An experimental section not in the general part}
\label{e:2}
% COMBINATION OF THE SECTIONS (COMMON TITLES, AND UP TO TWO LABELS)
\dummychapter % This is a dummy chapter which is here to combine all
% sections, subsections and subsections of two other
% chapters
% we set the tocdepth to -3 to avoid a Contents header (here, the
% default style of the document class are a priori used, as we did not
% modify the global toc style; so we have to get rid of the printing of
% the Contents headline)
\setcounter{tocdepth}{-3}
\localtableofcontents \label{toc:combined}
% These dummy sectioning units find their way to the .toc file, but they
% are assigned level 6, thus a priori do not appear either in the main
% TOC nor in any other TOC, unless their levels is re-assigned.
% (re-assignement of levels is a functionality of the etoc package)
\dummysection{A section not in the Experimental part}{g:0}{}
\dummysection{State of the Art}{g:1}{}
\dummysubsection{A}{g:1.1}{}
\dummysubsection{B}{g:1.2}{}
\dummysection{Evaluation of Peracrylate 1}{g:2}{e:1}
\dummysubsection{E}{g:2.1}{e:1.1}
\dummysubsection{F}{g:2.2}{e:1.2}
\dummysubsection{G}{g:2.3}{e:1.3}
\dummysubsection{H}{g:2.4}{e:1.4}
\dummysubsection{Various Methods: a very long subsection name to see what
happens then with the formatting inside the etoc table of
contents}{g:2.5}{e:1.5}
\dummysubsubsection{Method A}{}{e:1.5.1}
\dummysubsubsection{Method B}{}{e:1.5.2}
\dummysection{An experimental section not in the general part}{}{e:2}
\end{document}
先前的答案:
难度还取决于人们准备在源头上添加多少额外标记。
该方法(在此更新中得到简化:早期版本有一个两个参数命令,\Refs
而不是现在使用的一个参数\ExtraRef
)依赖于:
\label
对每个相关分段单元使用\ExtraRef {elabel}
用户必须将其插入章节的节和子节名称中,General
以引用Experimental
章节中的相应数据。该命令\ExtraRef
最初定义为不执行任何操作。包的使用埃托克然后根据
.toc
文件中可用的数据完成这项工作。
在进一步描述如何
etoc
使用之前,我想指出的是,使用同样的技术,我认为可以轻松实现一些略有不同但更方便的功能:目录将与往常一样,只是右侧有一个额外的列。在此列中,See also:
一些(但不是全部)称为分段单元,将有额外的页面或部分(小节等)编号,用于文档其他位置的相关材料。这些额外的数据将来自用户放入适当版本的标签\ExtraRef
。
这里的使用的方面etoc
:
声明了章节的本地目录
General
,它不打印在该章节中,而是紧接着主目录之后[并且为此\ExtraRef
重新定义为\pageref
用于“实验”标签]。主目录与课程默认设置相同,
\tableofcontents
指示仅打印章节和部分。接下来是本地目录,由其管理,
etoc
其中包含重复的页面引用。有些内容只包含在
Experimental
章节中;因此,在相应的小节中还声明了第三个目录toc:ExtraExperimental
,并将其插入到已完成的内容之后toc:General
。我为这些小节选择了一种特殊的样式,它们的编号与其他小节的编号不连续,因为它们实际上只属于实验章节,而不是一般章节。
输出如下:
\documentclass{book}% used to have chapters
% test of hyperref compatibility:
%\usepackage[linktoc=all,breaklinks]{hyperref} % if latex+dvips
\usepackage[linktoc=all]{hyperref}
\usepackage{etoc}
% This is written to the .toc file, but does not do anything until it is
% redefined
\DeclareRobustCommand\ExtraRef[1]{}
\begin{document}
% I used this to suppress the page numbering of the first page; this is because
% in the book class the \chapter command is invoked by the default \tableofcontents,
% and this resets the page style.
% \renewcommand{\etocaftertitlehook}{\thispagestyle{empty}}
\setcounter {secnumdepth}{3}
\setcounter {tocdepth}{1}
\tableofcontents
\begingroup
\parindent 0pt
\parfillskip 0pt
\leftskip 1.5cm
\rightskip 2cm
% redefining \ExtraRef
\DeclareRobustCommand\ExtraRef[1]
{\hfill\rlap
{\makebox[1cm]{\etocpage}%
\makebox[1cm]{\if\relax#1\relax\else\pageref{#1}\fi}}}
\etocsetstyle {section}
{\hfill{}\rlap{\makebox[1cm]{\textbf{Gen.}}%
\makebox[1cm]{\textbf{Exp.}}}\par}
{\leavevmode}
{\bfseries\llap{\makebox[1.5cm][l]{\etocnumber}}\etocname
\par
\smallskip}
{}
\etocsetstyle {subsection}
{}
{\leavevmode}
{\mdseries\llap{\makebox[1.5cm][l]{\etocnumber}}\etocname
\par}
{\addvspace{\medskipamount}}
\etocsetstyle {subsubsection}
{}
{\leavevmode}
{\mdseries \hspace{.5cm}\etocname\ (\etocnumber)
\hfill{}\rlap{\hspace{1cm}\makebox[1cm]{\etocpage}}\par}
{}
\setcounter {tocdepth}{3}
\etocsettocstyle {\vspace{1cm}\hrule\bigskip}{}
\tableofcontents \ref {toc:General}
\etocsettocstyle {\addvspace{-\medskipamount}}{}
\tableofcontents \ref {toc:ExtraExperimental}
\endgroup
\chapter{Introduction}
\cleardoublepage
\chapter{Objective}
\cleardoublepage
\chapter{General Part}
% This will not print anything but just prepares the local table of
% contents for this part, which is actually displayed earlier.
\setcounter{tocdepth}{-3}
\localtableofcontents \label {toc:General}
\setcounter{tocdepth}{3}
\section{State of the Art\ExtraRef{}}\label{g:1}
\subsection{A\ExtraRef{}}\label{g:1.1}
\clearpage
\subsection{B\ExtraRef{}}\label{g:1.2}
\clearpage
\section{Evaluation of Peracrylate 1\ExtraRef{e:1}}\label{g:2}
\subsection{E\ExtraRef{e:1.1}}\label{g:2.1}
\clearpage
\subsection{F\ExtraRef{e:1.2}}\label{g:2.2}
\clearpage
\subsection{G\ExtraRef{e:1.3}}\label{g:2.3}
\clearpage
\subsection{H\ExtraRef{e:1.4}}\label{g:2.4}
\clearpage
\subsection{Various Methods: a very long subsection name to see what happens
then with the
formatting inside the etoc table of contents\ExtraRef{e:1.5}}\label{g:2.5}
\chapter{Experimental Part}
\section{Evaluation of Peracrylate 1}\label{e:1}
\subsection{E}\label{e:1.1}
\clearpage
\subsection{F}\label{e:1.2}
\clearpage
\subsection{G}\label{e:1.3}
\clearpage
\subsection{H}\label{e:1.4}
\clearpage
\subsection{Various Methods: a very long subsection name to see what happens
then with the
formatting inside the etoc table of contents}\label{e:1.5}
\setcounter{tocdepth}{-3}
\localtableofcontents \label {toc:ExtraExperimental}
\setcounter{tocdepth}{3}
\subsubsection{Method A}%\label{e:1.5.1} (label not used)
\subsubsection{Method B}%\label{e:1.5.2} (label not used)
\end{document}