在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

側TOC

答案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}

相關內容