I am trying to simulate default TOC using package etoc
(I am happy with default TOC but I want some customizations)
I came up with the following setup (see MWE 1 and screenshot 1), but it has some problems:
- Etoc is exceeding left/right margin. How to fix this?;
- How to get section automatically aligned below the chapter label? I currently use a hspace for this (0.375cm) which I found out by experimenting, but it does not work in this MWE anymore (different font/size). How to get this always working (so no hard offset?)
- Chapter 2 alignment goes also wrong here.
How can I emulate default TOC (see MWE 2/screenshot 2) using etoc/etocsetstyle
?
MWE 1:
\documentclass{extbook}
\usepackage[a4paper,left=3cm,showframe]{geometry}
\usepackage{titlesec}
\usepackage{etoc}
\etocsetstyle{chapter}
{}
{ \normalsize\bfseries\addvspace{.5ex}\leavevmode}
{\llap{\etocnumber\hspace{0.75cm}}\etocname\hspace{10pt}\titlerule*[1pc]{.}\hspace{10pt}%
\makebox[0cm][l]{\makebox[0pt]{\etocpage}}\par}
{}
\etocsetstyle{section}
{}
{ \normalsize\addvspace{.5ex}\leavevmode}
{\llap{}\textit{\etocnumber\hspace{0.375cm}\etocname}\hspace{10pt}\titlerule*[1pc]{.}\hspace{10pt}%
\makebox[0cm][l]{\makebox[0pt]{\etocpage}}\par}
{}
\etocsettocstyle{\chapter*{Contents}}{}
\setcounter{tocdepth}{1}
\setcounter{secnumdepth}{2}
\begin{document}
\tableofcontents
\chapter{Test1}
\section{Test1.1}
\section{Test1.2}
\chapter{Test2}
\section{Test2.1}
\end{document}
MWE2:
\documentclass{extbook}
\usepackage[a4paper,left=3cm,showframe]{geometry}
\begin{document}
\tableofcontents
\chapter{Test1}
\section{Test1.1}
\section{Test1.2}
\chapter{Test2}
\section{Test2.1}
\end{document}