在 kaobook 类模板中,我已成功添加了子小节;但我该怎么做才能在 kaobook 侧目录中显示子小节?

在 kaobook 类模板中,我已成功添加了子小节;但我该怎么做才能在 kaobook 侧目录中显示子小节?
%\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

侧目录

答案1

当使用 ToC 边距时,该类kaobook不会定义子小节的条目。要做到这一点,需要重新定义相当长的\magintoc命令。

(1) \margintoc将在边距中插入本地目录。您可以使用可选参数将其向上或向下移动。例如,\margintoc[-0.6cm]与文本对齐

(2)要抑制特定本地目录的子部分,请使用

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

相关内容