1

I am using the etoc package to create local TOCs, however, for some reason, when using \etocsetstyle to set the style for some levels, affects the stype of others. More concretely: when I define styles that way for example for Chapters, Sections, and Subsections, the indentation at the beginning of the TOC entries "bleeds" into the indentation of the following ones. Here is an 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}

enter image description here

1 Answer 1

1

as far as I understand the first argument of \etocsetstyle{section}{first}{2}{3}{last} is executed only once when a section is first encountered, say after a chapter. So if some subsection changes \parindent after that it does not get reset. Thus one way appears to be to limite the scope via \begingroup/\endgroup to changes. Or any other way to restore which should happen in {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}

table of contents with correct indentation

I remarked some strange \hbox{\hbox to 1.5ex{\hss\hss}} which may come from some other stuff you simplified. Perhaps you mean \makebox[1.5ex]{} there simply? or perhaps even some \hspace{1.5ex}? I am not too familiar with the Plain TeX that etoc's doc seems to use preferentially.

1
  • Thanks a lot, this works! Regarding your question: honestly, I don't exactly know what \hbox{\hbox to 1.5ex{\hss\hss}} is supposed to do. That's how it used to be implemented in the kaobook template, although I just noticed that this is no longer the case in the newest version.
    – mapf
    Mar 26, 2023 at 8:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .