[Tex/LaTex] titletoc: How to format mini/partial tocs for each section (hspacing, vspace of entries)

table of contentstitletoc

I would like to have partial tocs (mini-tocs) for each section. I would like to achieve this with the titletoc package. As you can see from the code below, it pretty much does the job but the problem is that the settings for the main toc in the beginning do not necessarily apply for the mini-tocs. For example, the mini-toc is indented like the corresponding sub-toc of the main toc — of course that's not what one wants… I would like it to be left aligned as the section heading. Another problem is that for the mini-tocs, I would like to have more space between the subsection entries (but no space between the subsubsection entries). How can I do this? As you can see, the first problem can be solved with an addmargin environment (which is a bit ugly though), but I couldn't figure out how to solve the second problem (adjusting the space between the subsection entries in the mini-tocs).

\documentclass[
paper=128mm:96mm]{scrartcl}
\linespread{1.12}

% font stuff
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\renewcommand{\familydefault}{\sfdefault}
\usepackage[american]{babel}

% page structure
\usepackage{calc}
\usepackage[includefoot,top=5.5mm,bottom=4.5mm,left=5.5mm,right=5.5mm,footskip=4mm]{geometry}
\usepackage{scrpage2}
\usepackage{titlesec}
\usepackage{titletoc}

%%% settings %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% page style and layout
\pagestyle{scrheadings}
\clearscrheadfoot

% enlarge font sizes of headings by two levels
\addtokomafont{section}{\huge}
\addtokomafont{subsection}{\LARGE}
\addtokomafont{subsubsection}{\Large}

% spacings
\titlespacing{\section}{0mm}{0ex plus 1ex minus .2ex}{0ex plus .2ex}
\titlespacing{\subsection}{0mm}{0ex plus 1ex minus .2ex}{-.2ex plus .2ex}
\titlespacing{\subsubsection}{0mm}{0ex plus 1ex minus .2ex}{-.4ex plus .2ex}
\setcounter{secnumdepth}{3}% add numbering down to subsubsection

% table of contents
\AtBeginDocument{\renewcaptionname{american}{\contentsname}{\hspace{-0.08em}\Large Outline}}% change name of toc
\setcounter{tocdepth}{3}
\titlecontents{section}[1.2em]{\addvspace{0.6em}\bfseries}{\contentslabel{1.2em}}{\hspace*{-1.2em}}{}[]% define format for section of toc; entries: section, left, above, before with label, before without label, filler and page, after
\titlecontents{subsection}[3em]{}{\contentslabel{1.8em}}{\hspace*{-1.8em}}{}[]% define format for subsection of toc; entries: section, left, above, before with label, before without label, filler and page, after
\titlecontents{subsubsection}[5.6em]{}{\contentslabel{2.6em}}{\hspace*{-2.6em}}{}[]% define format for subsubsection of toc; entries: section, left, above, before with label, before without label, filler and page, after


%%% document %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}
\tableofcontents
\clearpage
\section{Section 1}
\startcontents[]% kind
%\begin{addmargin}{-1.08em}% ugly but solves the first problem
\printcontents[]{}{2}{}% kind, prefix, top, init-code
%\end{addmargin}
\clearpage
\subsection{Subsection 1.1}
\subsubsection{Subsubsection 1.1.1}
\subsection{Subsection 1.2}
\section{Section 2}
\subsection{Subsection 2.1}
\subsubsection{Subsubsection 2.1.1}
\subsubsection{Subsubsection 2.1.2}
\subsection{Subsection 2.2}
\subsubsection{Subsubsection 2.2.1}
\subsubsection{Subsubsection 2.2.2}
\clearpage
\end{document}

Best Answer

For the "partial" ToC, use \titlecontents to define the formats psubsection and psubsubsection (note the prefix) and issue \printcontents[]{p}{2}{} in the document body. See p. 17 of the titlesec/titletoc documentation for details.

\documentclass[
paper=128mm:96mm]{scrartcl}
\linespread{1.12}

% font stuff
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\renewcommand{\familydefault}{\sfdefault}
\usepackage[american]{babel}

% page structure
\usepackage{calc}
\usepackage[includefoot,top=5.5mm,bottom=4.5mm,left=5.5mm,right=5.5mm,footskip=4mm]{geometry}
\usepackage{scrpage2}
\usepackage{titlesec}
\usepackage{titletoc}

%%% settings %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% page style and layout
\pagestyle{scrheadings}
\clearscrheadfoot

% enlarge font sizes of headings by two levels
\addtokomafont{section}{\huge}
\addtokomafont{subsection}{\LARGE}
\addtokomafont{subsubsection}{\Large}

% spacings
\titlespacing{\section}{0mm}{0ex plus 1ex minus .2ex}{0ex plus .2ex}
\titlespacing{\subsection}{0mm}{0ex plus 1ex minus .2ex}{-.2ex plus .2ex}
\titlespacing{\subsubsection}{0mm}{0ex plus 1ex minus .2ex}{-.4ex plus .2ex}
\setcounter{secnumdepth}{3}% add numbering down to subsubsection

% table of contents
\AtBeginDocument{\renewcaptionname{american}{\contentsname}{\hspace{-0.08em}\Large Outline}}% change name of toc
\setcounter{tocdepth}{3}
\titlecontents{section}[1.2em]{\addvspace{0.6em}\bfseries}{\contentslabel{1.2em}}{\hspace*{-1.2em}}{}[]% define format for section of toc; entries: section, left, above, before with label, before without label, filler and page, after
\titlecontents{subsection}[3em]{}{\contentslabel{1.8em}}{\hspace*{-1.8em}}{}[]% define format for subsection of toc; entries: section, left, above, before with label, before without label, filler and page, after
\titlecontents{subsubsection}[5.6em]{}{\contentslabel{2.6em}}{\hspace*{-2.6em}}{}[]% define format for subsubsection of toc; entries: section, left, above, before with label, before without label, filler and page, after
\titlecontents{psubsection}[1.8em]{\addvspace{0.6em}}{\contentslabel{1.8em}}{\hspace*{-1.8em}}{}[]% define format for section of toc; entries: section, left, above, before with label, before without label, filler and page, after
\titlecontents{psubsubsection}[4.4em]{}{\contentslabel{2.6em}}{\hspace*{-2.6em}}{}[]% define format for subsection of toc; entries: section, left, above, before with label, before without label, filler and page, after


%%% document %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}
\tableofcontents
\clearpage
\section{Section 1}
\startcontents[]% kind
\printcontents[]{p}{2}{}% kind, prefix, top, init-code
\clearpage
\subsection{Subsection 1.1}
\subsubsection{Subsubsection 1.1.1}
\subsection{Subsection 1.2}
\section{Section 2}
\subsection{Subsection 2.1}
\subsubsection{Subsubsection 2.1.1}
\subsubsection{Subsubsection 2.1.2}
\subsection{Subsection 2.2}
\subsubsection{Subsubsection 2.2.1}
\subsubsection{Subsubsection 2.2.2}
\clearpage
\end{document}