4

I would like to use package etoc for getting local toc at the start of each chapter. However, I struggle to:

  1. hide the title "Contents"
  2. add horizontal rules above and under this local toc entries
  3. typeset the chapter content (mini toc with text) immediately after the chapter heading not on the chapter third page (the second is blank)

\documentclass{scrbook}

\usepackage{lipsum}
\usepackage{etoc}

\begin{document}

\chapter{Chapter 1}
\localtableofcontents 

\section{Section 1}
\lipsum[1-20]
\section{Section 2}
\lipsum[1-20]

\end{document}

enter image description here

5

The \etocsettocstyle command provides means to set some stuff before and after the ToC, i.e. the horizontal rules. Using it in a very primitive way, it will also prevent the page break etc.

\documentclass{scrbook}

\usepackage{lipsum}
\usepackage{etoc}


\newlength\tocrulewidth
\setlength{\tocrulewidth}{1.5pt}

\begin{document}

\tableofcontents
\chapter{Chapter 1}
\begingroup
\parindent=0em
\etocsettocstyle{\rule{\linewidth}{\tocrulewidth}\vskip0.5\baselineskip}{\rule{\linewidth}{\tocrulewidth}}
\localtableofcontents 
\endgroup


\section{Section 1}
\lipsum[1-20]
\section{Section 2}
\lipsum[1-20]

\end{document}

enter image description here

  • Many thanks, I could never figure it out in that clean way. – Diaa Jun 4 '16 at 5:45
  • 1
    @DiaaAbidou: You're welcome -- yes, the etoc manual is quite overwhelming and sometimes a little bit tricky to find the relevant information – user31729 Jun 4 '16 at 5:50
  • I am sorry, but is it possible to left align the section entries for a bit more aesthetic look? – Diaa Jun 4 '16 at 11:28
  • 1
    @DiaaAbidou: I'll see what I can do – user31729 Jun 4 '16 at 14:19
  • 1
    The reason for the indent is that here etoc is in compatibilty mode and delegates to the scrbook class the typesetting. I found no option in the KOMA-script manual, but adding \def\scr@tso@section@indent{0pt} (within \makeatletter/\makeatother) before \localtableofcontents does the trick. If however subsections are present, then you probably want to reduce their indent too. A more complicated \edef\scr@tso@subsection@indent{\the\dimexpr\scr@tso@subsection@indent-\scr@tso@section@indent} (before the fix for sections) does the trick then. – user4686 Sep 10 '16 at 14:03
3

(moved from a comment)

This is only an addendum to Christian's answer. The indent is explained from the fact that here etoc is in compatibilty mode and delegates to the scrbook class the typesetting. Hence sections in local TOCs appear as they would in the main TOC.

The etoc manual has an example of use \KOMAoptions{toc=left} but this does not work here as it needs some KOMA code which the \etocsettocstyle{..}{..} command has overwritten. I looked at scrbook code and found out that doing

\makeatletter
  \def\scr@tso@section@indent{0pt}
\makeatother
\localtableofcontents 

solves the indent problem. However, a subsection would still be indented as in the main TOC. For lack of better solution I can propose:

\makeatletter
  \edef\scr@tso@subsection@indent
    {\the\dimexpr\scr@tso@subsection@indent-\scr@tso@section@indent}
  \def\scr@tso@section@indent{0pt}
\makeatother
\localtableofcontents 

There may be an interface in KOMA to these indents but I did not (immediately) figure out how.

Full code (from Christian's answer):

\documentclass{scrbook}

\usepackage{lipsum}
\usepackage{etoc}


\newlength\tocrulewidth
\setlength{\tocrulewidth}{1.5pt}

\begin{document}

\tableofcontents
\chapter{Chapter 1}

\begingroup
\parindent=0em
\etocsettocstyle{\rule{\linewidth}{\tocrulewidth}\vskip0.5\baselineskip}{\rule{\linewidth}{\tocrulewidth}}
\makeatletter
  \edef\scr@tso@subsection@indent
    {\the\dimexpr\scr@tso@subsection@indent-\scr@tso@section@indent}
  \def\scr@tso@section@indent{0pt}
\makeatother
\localtableofcontents 
\endgroup


\section{Section 1}
\lipsum[1-20]
\subsection{subsection 1.1}
\section{Section 2}
\lipsum[1-20]

\end{document}

enter image description here

  • (+1) ..................... (filler) – user31729 Sep 10 '16 at 14:19
  • @ChristianHupfer coincidentally I added to the just uploaded (not yet on mirrors) slightly extended etoc manual some new sample code which in particular shows how to add these rules above and below in a non-separable by pagebreak way. (this is another topic) – user4686 Sep 10 '16 at 14:21
  • @ChristianHupfer the updated etoc manual in fact contains a conversion into etoc lingua of the book class code; thus all internals are revealed and can be customized at will, and in particular be adapted suitably for local tables of contents. – user4686 Sep 10 '16 at 14:26
  • That is very nice and helpful indeed. Any progresses to support local .lof etc. or is this the next project with elof and elot and elistofanything packages? ;-) – user31729 Sep 10 '16 at 14:27
  • @ChristianHupfer I agree that etoc should apply to list of figures and list of tables. It does not because when I started doing etoc I had never seen any personal utility in including list of figures or list of tables in my manuscripts ... and I basically did not care and hardly knew about them. Nevertheless, supporting \listoffigures, \listoftables is now on etoc's agenda indeed... but this can't be soon. (perhaps TL2017, never underestimate the pressure induced on package authors via this mechanism of yearly releases!) – user4686 Sep 10 '16 at 18:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.