0
%\setcounter{secnumdepth}{\kao@secnumdepth} % Set section numbering 
%depth
\setcounter{secnumdepth}{3}
\counterwithin*{sidenote}{chapter} % Uncomment to reset the sidenote counter at each chapter
%\counterwithout{sidenote}{chapter} % Uncomment to have one sidenote counter for the whole document

side TOC

1
  • Thank you for your feedback!! If the answer meets your requirement, please accept by checking the green tickmark on left side of the answer. Commented May 15, 2022 at 22:00

1 Answer 1

1

The kaobook class does not define the entries for the subsubsections when the ToC margin is used. To do so requires redefining the rather long \magintoc command.

(1) \margintoc will insert the local ToC in the margin. You can move it up or down using the optional parameter. For example \margintoc[-0.6cm] to align with the text

(2) To suppress the sub-subsections of a particular local ToC use

\etocsetnexttocdepth{2}
\setcounter{margintocdepth}{2}% 
\margintoc

c

% !TeX TS-program = pdflatex

\documentclass[
    secnumdepth=3, % <<<<<<<<<<<<<<<<<<<<<<<<< added for subsubsections
]{kaobook}

\usepackage{kantlipsum}% ONLY for dummy text

%%*********************************************************** added <<<<<<<<<<<<<<<<<<<<<<<<<<<<<
\setcounter{margintocdepth}{3}% 3 for subsubsections; 2 for subsection
\etocstandarddisplaystyle % "toc display" as if etoc was not loaded
\etocstandardlines % "toc lines as if etoc was not loaded
%%%%% Command to print a table of contents in the margin
\RenewDocumentCommand{\margintoc}{O{\mtocshift}}{ % The first parameter is the vertical offset; by default it is \mtocshift
    \begingroup%
    \etocsetlevel{section}{6}
    \etocsetlevel{subsection}{6}
    \etocsetlevel{mtocsection}{1}
    \etocsetlevel{mtocsubsection}{2}
    \etocsetlevel{mtocsubsubsection}{3} % <<<<<<<<<<<<<<<<
    
    % Define default widths
    \def\margintocnumwidth{-.8mm}%
    \def\margintocpagenumwidth{8pt}%
    \setlength{\RaggedRightParfillskip}{0pt}
    
    % Dry run to get the needed widths
    \etocsetstyle{mtocsection}%
    {}%
    {\setbox0\hbox{{\usekomafont{section}\small\etocthenumber\kern.8mm}}%%
        \setbox1\hbox{{\usekomafont{section}\small\etocthepage}}}%
    {\ifdim\wd0>\margintocnumwidth \edef\margintocnumwidth{\the\wd0} \fi%%
        \ifdim\wd1>\margintocpagenumwidth \edef\margintocpagenumwidth{\the\wd1} \fi}%
    {}%
    \etocsetstyle{mtocsubsection}%
    {}%
    {\setbox0\hbox{{\usekomafont{section}\small\mdseries\etocthenumber\kern.8mm}}%
        \setbox1\hbox{{\usekomafont{section}\small\mdseries\etocthepage}}}%
    {\ifdim\wd0>\margintocnumwidth \edef\margintocnumwidth{\the\wd0} \fi%
        \ifdim\wd1>\margintocpagenumwidth \edef\margintocpagenumwidth{\the\wd1} \fi}%
    {}%
    \etocsetstyle{subsubsection}% <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    {}%
    {\setbox0\hbox{{\usekomafont{section}\small\mdseries\etocthenumber\kern.8mm}}%
        \setbox1\hbox{{\usekomafont{section}\small\mdseries\etocthepage}}}%
    {\ifdim\wd0>\margintocnumwidth \edef\margintocnumwidth{\the\wd0} \fi%
        \ifdim\wd1>\margintocpagenumwidth \edef\margintocpagenumwidth{\the\wd1} \fi}%
    {}%
    \etocsettocstyle{}{%
        \global\let\margintocnumwidth\margintocnumwidth%
        \global\let\margintocpagenumwidth\margintocpagenumwidth%
    }%
    \localtableofcontents%
    
    % Set the style for section entries
    \etocsetstyle{mtocsection}%
    {\parindent 0pt \parskip 2.5pt \parfillskip 0pt \RaggedRight}%
    {\leftskip \margintocnumwidth \rightskip \margintocpagenumwidth}%
    {\makebox[0pt][r]{\makebox[\margintocnumwidth][l]{\etocnumber}}\etocname\nobreak\leaders\hbox{\hbox to 1.5ex {\hss.\hss}}\hfill\rlap{\makebox[\margintocpagenumwidth][r]{\etocpage}}\par}%
    {}%
    % Set the style for subsection entries
    \etocsetstyle{mtocsubsection}%
    {\parindent 0pt \parskip 0pt \parfillskip 0pt \RaggedRight}%
    {\leftskip \margintocnumwidth \rightskip \margintocpagenumwidth}%
    {\makebox[0pt][r]{\makebox[\margintocnumwidth][l]{\mdseries\etocnumber}}{\mdseries\etocname\nobreak\leaders\hbox{\hbox to 1.5ex {\hss.\hss}}\hfill\rlap{\makebox[\margintocpagenumwidth][r]{\mdseries\etocpage}}}\par}%
    {\parskip 2.5pt}%
    % Set the style for subsubsection entries <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    \etocsetstyle{mtocsubsubsection}%
    {\parindent 0pt \parskip 0pt \parfillskip 0pt \RaggedRight}%
    {\leftskip \margintocnumwidth \rightskip \margintocpagenumwidth}%
    {\makebox[0pt][r]{\makebox[\margintocnumwidth][l]{\mdseries\etocnumber}}{\mdseries\etocname\nobreak\leaders\hbox{\hbox to 1.5ex {\hss.\hss}}\hfill\rlap{\makebox[\margintocpagenumwidth][r]{\mdseries\etocpage}}}\par}%
    {\parskip 2.5pt}%
    % Set the global style of the toc
    \etocsettocstyle{\usekomafont{section}\small}{}%
    \etocsetnexttocdepth{\themargintocdepth}%
    % Print the table of contents in the margin
    \marginnote[#1]{\localtableofcontents}%
    \FloatBarrier%
    \endgroup%
}

\setcounter{tocdepth}{3}% 3 >> add subsubsections in main ToC <<<<<

\begin{document}
    
\tableofcontents% main ToC  
    
\mainmatter % 

\chapter{Introduction}

\etocsetnexttocdepth{3}% <<<<<<<<<<<<<<<<<<<<<<<<<<<<
\setcounter{margintocdepth}{3}% 
\margintoc[-0.6em]% <<<<<<<<<<<<<<<<<<<<<<<<<<<<

1. \kant[1]
\section{The main ideas}
\subsection{The sub--main idea}
3. \kant[3]
\subsubsection{The sub--sub--main idea}
4. \kant[4]
\section{What is does}
5. \kant[5]
\section{What does not}
\section{How to use}

\end{document}
1
  • Many Thanks Simon Dispa; based on your help I've managed to fix my file. God bless You. Commented May 14, 2022 at 15:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .