4

I like to get a toc at beginning of some of my sections, like in beamer where I can use \tableofcontents[currentsection] is there a possibility in scrartcl?

Something like this:

\documentclass[10pt,a4paper]{scrartcl}
\usepackage[ngerman]{babel} 
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\begin{document}

\tableofcontents %complete

\section{First}

\section{Second}
\tableofcontents %just subsection and subsubsection
\subsection{SecondSub}
\subsubsection{please}
\subsection{this}
\subsection{SecondSub2}
\subsection{parts}

\section{Third}
\subsection{another}

\end{document}

Looks like:

Inhaltsverzeichnis %complete

1 First

2 Second
2.1 SecondSub.......................2
2.1.1 please........................2
2.1.2 this..........................2
2.2. SecondSub2.....................3
2.2.1 parts.........................4

3 Third
3.1 another ........................5


1 First

2 Second

Inhaltsverzeichnis %just subsection and subsubsection
2.1 SecondSub.......................2
 2.1.1 please........................2
 2.1.2 this..........................2
2.2. SecondSub2.....................3
 2.2.1 parts.........................4

2.1 SecondSub

2.1.1 please 

2.1.2 this

2.2. SecondSub2

2.2.1 parts


3 Third

3.1 another
  • 1
    Welcome. See package etoc – Marco Daniel Mar 31 '17 at 9:47
4

Here's an example using etoc. It's just a starting point.

\documentclass[10pt,a4paper]{scrartcl}
\usepackage[ngerman]{babel} 
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{etoc}
\etocsettocstyle{\subsection*{\contentsname}}{}

\begin{document}

\tableofcontents 

\section{First}

\section{Second}
\localtableofcontents
\subsection{SecondSub}
\subsubsection{please}
\subsection{this}
\subsection{SecondSub2}
\subsection{parts}

\section{Third}
\subsection{another}

\end{document}

enter image description here

  • Thanks, sorry was busy. It's what I was looking for and it works :) – kir Apr 5 '17 at 9:15
2

You could use KOMA-Script's alpha package scrwfile and a local redefinition of some \l@… commands and local changes of tocdepth:

\documentclass[10pt,a4paper]{scrartcl}
\usepackage[ngerman]{babel} 
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{scrwfile}

\makeatletter
\newcounter{sectiontocdepth}
\setcounter{sectiontocdepth}{\subsubsectiontocdepth}
\newcommand*{\sectiontoc}{%
  \edef\reserved@a{\noexpand\setcounter{tocdepth}{\the\value{tocdepth}}}%
  \begingroup
    \setcounter{tocdepth}{\sectiontocdepth}%
    \let\l@part\@gobbletwo
    \def\l@section##1##2{%
      \begingroup
        \def\numberline####1{%
          \ifstr{####1}{\thesection}{%
            \setcounter{tocdepth}{\value{sectiontocdepth}}%
          }{%
            \setcounter{tocdepth}{\sectiontocdepth}%
          }%
        }%
        \sbox\@tempboxa{##1}%
      \endgroup
    }%
    \listoftoc*{toc}%
  \endgroup
  \reserved@a
}
\makeatother

\setcounter{sectiontocdepth}{\subsubsectiontocdepth}

\begin{document}

\tableofcontents %complete

\section{First}

\section{Second}
\sectiontoc
\subsection{SecondSub}
\subsubsection{please}
\subsection{this}
\subsection{SecondSub2}
\subsection{parts}

\section{Third}
\subsection{another}

\end{document}

page with table of contents and section table of contents

Note, that it works only for numbered sections.

If you want a heading above the section ToC, replace

\listoftoc*{toc}

by

\setuptoc{toc}{leveldown}%
\listoftoc{toc}%

and you'll get:

section toc with headline

Alpha package scrwfile is used to avoid \tableofcontents (and \listoftoc* or listoftoc) to remove the contents of the toc file. See the manual for possible issues.

1

Question Table of contents with current section accentuated (not in Beamer) was marked as an exact duplicate which I don't think it is. (or rather perhaps the question is, but the existing answers are in slightly different spirit, it seems; here the section itself is part of the printed table of contents)

Thus I am providing here an answer to that question.

\documentclass[a4paper]{article}
\usepackage{xcolor}
\usepackage{etoc}
\usepackage{hyperref}

\makeatletter
\DeclareRobustCommand{\SectionFromToc}[1]{\ifnum#1=\value{section}%
        \color{black}%
        \expandafter\@SectionFromToc\else\color{gray}\fi}

% without hyperref, do not use #4 here.
\def\@SectionFromToc \contentsline#1#2#3#4{%
    \section*{{\def\mysecnumber{\makebox[1.5em][l]}#2}}
}

\DeclareRobustCommand\mysecnumber[1]{}

\makeatother

\newcommand\mysection[1]{%
 \clearpage
 \refstepcounter{section}%
 \addtocontents{toc}{\SectionFromToc{\the\value{section}}}%
 \addcontentsline{toc}{section}{\mysecnumber{\the\value{section}}#1}%
 \tableofcontents
}                    
\etocsettocstyle{}{\clearpage}

\begin{document}

\mysection{Section 1}

Content of Section 1

\mysection{Section 2}

Content of Section 2

\mysection{Section 3}

Content of Section 3

\mysection{Section 4}

Content of Section 4
\end{document}

enter image description here

In order to give a better idea of what this gives as result, here is with rather

\etocsettocstyle{}{\vspace{2\baselineskip}}

enter image description here

Here is with some added subsections:

enter image description here

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.