# Currentsection TOC in scrartcl?

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}
\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.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.2 this..........................2
2.2. SecondSub2.....................3
2.2.1 parts.........................4

2.1 SecondSub

2.1.2 this

2.2. SecondSub2

2.2.1 parts

3 Third

3.1 another

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

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}
\subsection{this}
\subsection{SecondSub2}
\subsection{parts}

\section{Third}
\subsection{another}

\end{document}


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

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}
\subsection{this}
\subsection{SecondSub2}
\subsection{parts}

\section{Third}
\subsection{another}

\end{document}


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:

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.

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}%
\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}


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

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


Here is with some added subsections: