我正在使用etoc
包来创建本地目录,但是,出于某种原因,当使用它\etocsetstyle
来设置某些级别的样式时,会影响其他级别的样式。更具体地说:当我以这种方式定义样式(例如章节、部分和小节)时,目录条目开头的缩进会“渗入”到以下条目的缩进中。这是一个 MWE:
\documentclass{scrbook}
\usepackage{etoc}
% Set the style for chapter entries
\etocsetstyle{chapter}%
{\parindent 0pt \parskip 0pt}%
{\leftskip 0pt}%
{\makebox[.5cm]{}%
\hangindent=0.5cm\etoclink{\etocthename}\nobreak\hbox{\hbox to 1.5ex {\hss\hss}}\hfill\makebox[5mm][l]{\etocpage}\nobreak%
\par}%
{}%
% Set the style for section entries
\etocsetstyle{section}%
{\parindent 20pt \parskip 0pt}%
{\leftskip 0pt}%
{\makebox[.5cm]{}%
\hangindent=0.5cm\etoclink{\etocthename}\nobreak\hbox{\hbox to 1.5ex {\hss\hss}}\hfill\makebox[5mm][l]{\etocpage}\nobreak%
\par}%
{}%
% Set the style for subsection entries
\etocsetstyle{subsection}%
{\parindent 40pt \parskip 0pt}%
{\leftskip 0pt}%
{\makebox[.5cm]{}%
\hangindent=0.5cm\etoclink{\etocthename}\nobreak\hbox{\hbox to 1.5ex {\hss\hss}}\hfill\nobreak%
\par}%
{}%
\begin{document}
\tableofcontents
\part{First Part}
\localtableofcontents
\chapter{Part 1}
\section{Section 1}
\section{Section 2}
\chapter{Part 2}
\section{Section 1}
\section{Section 2}
\subsection{Subsection 1}
\subsection{Subsection 2}
\section{Section 3}
\chapter{Part 3}
\end{document}
答案1
据我所知, 的第一个参数\etocsetstyle{section}{first}{2}{3}{last}
仅在第一次遇到某个部分时执行一次,例如在章节之后。因此,如果某个子部分\parindent
在那之后发生变化,它不会被重置。因此,一种方法似乎是通过更改来限制范围\begingroup/\endgroup
。或者任何其他恢复应该在 中发生的方式{last}
。
\documentclass{scrbook}
\usepackage{etoc}
% Set the style for chapter entries
\etocsetstyle{chapter}%
{\begingroup
\parindent 0pt \parskip 0pt}%
{\leftskip 0pt}%
{\makebox[.5cm]{}%
\hangindent=0.5cm
\etoclink{\etocthename}\nobreak\hbox{\hbox to 1.5ex {\hss\hss}}%
\hfill\makebox[5mm][l]{\etocpage}\nobreak%
\par}%
{\endgroup}%
% Set the style for section entries
\etocsetstyle{section}%
{\begingroup
\parindent 20pt \parskip 0pt}%
{\leftskip 0pt}%
{\makebox[.5cm]{}%
\hangindent=0.5cm
\etoclink{\etocthename}\nobreak\hbox{\hbox to 1.5ex {\hss\hss}}%
\hfill\makebox[5mm][l]{\etocpage}\nobreak%
\par}%
{\endgroup}%
% Set the style for subsection entries
\etocsetstyle{subsection}%
{\begingroup
\parindent 40pt \parskip 0pt}%
{\leftskip 0pt}%
{\makebox[.5cm]{}%
\hangindent=0.5cm
\etoclink{\etocthename}\nobreak\hbox{\hbox to 1.5ex {\hss\hss}}\hfill\nobreak%
\par}%
{\endgroup}%
\begin{document}
\tableofcontents
\part{First Part}
\localtableofcontents
\chapter{Part 1}
\section{Section 1}
\section{Section 2}
\chapter{Part 2}
\section{Section 1}
\section{Section 2}
\subsection{Subsection 1}
\subsection{Subsection 2}
\section{Section 3}
\chapter{Part 3}
\end{document}
我注意到一些奇怪的内容\hbox{\hbox to 1.5ex{\hss\hss}}
,可能来自于您简化的其他内容。也许您的意思是“\makebox[1.5ex]{}
那里简单”?或者甚至“一些\hspace{1.5ex}
”?我不太熟悉etoc
Doc 似乎优先使用的 Plain TeX。