我正在尝试使用该minitoc
包为某个小节生成目录。从我对minitoc
文档的阅读来看,这似乎不太可能用来实现minitoc
,因此我愿意听取使用minitoc
或任何其他可以实现此目标的包的建议:
\documentclass{article}
\usepackage[layout=letterpaper,margin=1in]{geometry}
\usepackage{fancyhdr}
\usepackage{minitoc}
\setcounter{secttocdepth}{5}
\begin{document}
\dosecttoc
\faketableofcontents
\fancyfoot[L]{Revision 0.2.3 -- Dec 18, 2012}
\pagestyle{fancyplain}
\section{Small Section}
\section{Huge Section}
\subsection{Large Subsection 1}
This should be the TOC for just this {\bf subsection}:
\secttoc
\subsubsection{Thing 1}
\subsubsection{Thing 2}
\subsubsection{Thing 3}
\subsection{Large Subsection 2}
This should be the TOC for just this {\bf subsection}:
\secttoc
\subsubsection{Thing A}
\subsubsection{Thing B}
\subsubsection{Thing C}
\end{document}
答案1
你可以尝试etoc
。我不知道minitoc
同时使用是否会导致文档其他地方发生冲突。对于此测试,注释掉所有命令minitoc
不会对结果产生影响,但我保留了它们,以防整个文档需要该minitoc
功能。
编辑:我添加了一个宏来设置目录的右边距,就像标准文档类排版一样。最初,我将目录放在了一个小页面中,但需要另一种方法来允许分页。
笔记:我的编辑经历了连续的阶段,因为实施过程中存在错误。但我认为现在基本上没问题了。
编辑2:我添加了另一种完全不同的方法来获取目录所需的边距。
\documentclass{article}
\usepackage[layout=letterpaper,margin=1in]{geometry}
\usepackage{fancyhdr}
\usepackage{minitoc} % left in case it is needed elsewhere
\setcounter{secttocdepth}{5} % idem
\usepackage{etoc}
% macro to set up a right margin for a TOC typeset
% with the standard document classes.
% A simpler method would be to put the TOC in a minipage,
% but then it could not extend across pages.
% The hack is compatible with the use of hyperref.
% Put the definition in the preamble and use the
% command in the *body* of the document.
% example:
% \SetTOCrightmargin{.1\linewidth}
% \tableofcontents
\makeatletter
\newif\ifTOC@marginpatched
\newcommand{\SetTOCrightmargin}[1]{%
\ifTOC@marginpatched\else
\let\old@pnumwidth\@pnumwidth
\let\old@dottedtocline\@dottedtocline
\def\@dottedtocline##1##2##3##4##5{%
\old@dottedtocline{##1}{##2}{##3}{##4}{##5\hskip\TOC@rightmargin}}
\let\old@l@part\l@part
\def\l@part##1##2{\old@l@part{##1}{##2\hskip\TOC@rightmargin}}
% For the book/report class, replace all three occurences of
% section by chapter in the next two lines
\let\old@l@section\l@section
\def\l@section##1##2{\old@l@section{##1}{##2\hskip\TOC@rightmargin}}
\fi
\TOC@marginpatchedtrue
\edef\TOC@rightmargin{#1}%
\dimen0=\old@pnumwidth\relax
\advance\dimen0 by #1\relax
\edef\@pnumwidth{\the\dimen0}}
\makeatother
\begin{document}
\dosecttoc % idem
\faketableofcontents % idem
\fancyfoot[L]{Revision 0.2.3 -- Dec 18, 2012}
\pagestyle{fancyplain}
\section{Small Section}
\section{Huge Section}
\subsection{Large Subsection 1}
This should be the TOC for just this {\bf subsection}:
%\secttoc
% this is a quick try (much perfectible) to emulate the style
% of the minitocs as displayed in the OP message.
\etocsettocstyle{\subsection*{\contentsname}\hrule\smallskip
\begin{minipage}{.95\linewidth}}
{\end{minipage}\medskip\hrule}
\localtableofcontents
\subsubsection{Thing 1}
\subsubsection{Thing 2}
\subsubsection{Thing 3}
\subsection{Large Subsection 2}
This should be the TOC for just this {\bf subsection}:
%\secttoc
% when using \SetTOCrightmargin, we use a simpler \etocsetstyle:
\etocsettocstyle
{\subsection*{\contentsname}\hrule\smallskip}
{\nobreak\medskip\hrule\bigskip}
\SetTOCrightmargin{.05\linewidth} % or any desired length
\localtableofcontents
\subsubsection{Thing A}
\subsubsection{Thing B}
\subsubsection{Thing C}
% we can then also print the complete table of contents
\tableofcontents
% with etoc we can do it many times
\SetTOCrightmargin{.5\linewidth} % the right margin is now .5\linewidth
\tableofcontents
\end{document}
我最初使用 来minipage
快速解决设置目录行右边距的问题。但这种方法的缺陷是目录无法跨页扩展。然后我提出了另一种方法,没有这个缺陷,但它仅适用于本地目录,如上面的最小示例所示。
\etocsettocstyle
{\subsection*{\contentsname}\hrule\smallskip
\everypar{\rightskip.1\linewidth}}
{\nobreak\medskip\hrule\bigskip}
对于更一般的事情,这很快就会失效,所以我添加了一个宏\SetTOCrightmargin
来提供一般解决方案。使用此宏时,只需设置:
\etocsettocstyle
{\subsection*{\contentsname}\hrule\smallskip}
{\nobreak\medskip\hrule\bigskip}
下面的图像没有更新,但如果你排版代码,你会看到两个完整的目录确实有正确的右边距,而第二个目录在第 1 页的底部断开。
该宏与包无关etoc
:您可以在标准文档类中使用它。为了保持本地的效果\SetTOCrightmargin
,可以将其(当然与下一个目录一起)放在一个组中。然而它的第一的使用必须必须处于顶层。
上面的宏\SetTOCrightmargin
可以在标准文章类中使用,无需任何包。现在有另一个看起来更简单的宏,但它需要包etoc
。此外,它还允许设置左边距。此宏仅在其“兼容”模式下使用etoc
,这意味着它会将目录条目排版为与没有它时完全相同。
小说\etocsettocmargins
有三个参数。第一个是可选的,它允许取消条目的固有右移当地的目录:1.5em
在章节、3.8em
子章节中选择。默认值为0pt
,适用于全球的TOC,或用于文档部分的本地 TOC。然后有两个强制参数,第一个是所需的左边距,第二个是所需的右边距(意味着页码就位于此右边距的左侧)。
在课程测试中,我发现不兼容当minitoc
和etoc
一起使用时,文档中包含\part
命令。因此,我在这里完全删除了所有minitoc
内容,只是为了展示当使用文档中的部分时会发生什么。
\documentclass{article}
\usepackage[layout=letterpaper,margin=1in]{geometry}
%\usepackage[linktoc=all]{hyperref}
\usepackage{fancyhdr}
\usepackage{etoc}
\newcommand{\etocsettocmargins}[3][0pt]{%
\renewcommand{\etocaftertitlehook}
{\let\oldpar\par\def\par{%
\advance\leftskip by -#1\relax
\advance\leftskip by #2\relax
\advance\rightskip by #3\relax\oldpar}}}
\newcommand{\etocresettocmargins}{%
\renewcommand{\etocaftertitlehook}{\relax}}
\begin{document}
\fancyfoot[L]{Revision 0.2.3 -- Dec 18, 2012}
\pagestyle{fancyplain}
\etocsettocmargins{.1\linewidth}{.1\linewidth}
\etocsettocstyle
{\section*{\hskip.1\linewidth\contentsname}}
{}
\tableofcontents
\part{FIRST PART}
\section{Small Section but which has a long name to see if it works, actually it
has a very very long name}
\part{SECOND PART}
\section{Huge Section}
Here is the TOC for this section:
\etocsettocstyle{\centering\subsection*{Contents of this section}}{}
\etocsettocmargins[1.5em]{.275\linewidth}{.275\linewidth}
\localtableofcontents
\subsection{Large Subsection 1}
This should be the TOC for just this {\bf subsection}. Its entries are centered
with the left and right margins and equal to 1/20th of the line width.
\etocsettocmargins[3.8em]{.05\linewidth}{.05\linewidth}
\etocsettocstyle
{\subsubsection*{Contents of this subsection}\hrule\smallskip}
{\nobreak\medskip\hrule\bigskip}
\localtableofcontents
\subsubsection{Thing 1}
1
\subsubsection{Thing 2}
2
\subsubsection{Thing 3 also has a very very very long name even longer than
would be reasonable let's make it even longer}
3
\subsection{Large Subsection 2}
This should be the TOC for just this {\bf subsection}. The technique of the
minipage is the simplest:
\begin{center}
\begin{minipage}[c]{0.6\linewidth}
\etocsettocmargins[3.8em]{0pt}{0pt}
\localtableofcontents
\end{minipage}
\end{center}
\subsubsection{Thing A also has a very very very long name even longer than
would be reasonable and truly it is a very very long name}
A
\subsubsection{Thing B}
B
\subsubsection{Thing C}
C
\end{document}