feat(documentclass): add auto page number width option and improve TOC dot leaders

This commit is contained in:
2025-11-02 02:46:59 +07:00
parent 0530ce0cea
commit 9be2afb558

View File

@@ -14,6 +14,7 @@
% section number depth and tocdepth
\DeclareStringOption[3]{sectiondepth}
\DeclareStringOption[3]{tocdepth}
\DeclareStringOption[fixed]{pnumwidth}
% cover page style
\DeclareStringOption[default]{cover} % default is 'custom'
@@ -307,6 +308,30 @@
% \renewcommand{\thesection}{\textup{\Roman{chapter}}.\arabic{section}}
% Dot leaders, spacing, indentation
\makeatletter
\ifdefstring{\skripsikvopt@pnumwidth}{auto}{%
% Thanks to https://tex.stackexchange.com/a/397295/270151 for clever solution to fix the fixed length \@pnumwidth problem to auto-like width
% \patchcmd{<cmd>}{<search>}{<replace>}{<success>}{<failure>}
\patchcmd{\cftchapfillnum}% <cmd>
{\makebox[\@pnumwidth][\cftpnumalign]}% <search>
{}% <replace>
{}{}% <success><failure>
\patchcmd{\cftsecfillnum}% <cmd>
{\makebox[\@pnumwidth][\cftpnumalign]}% <search>
{}% <replace>
{}{}% <success><failure>
\patchcmd{\cftsubsecfillnum}% <cmd>
{\makebox[\@pnumwidth][\cftpnumalign]}% <search>
{}% <replace>
{}{}% <success><failure>
\patchcmd{\cftsubsubsecfillnum}% <cmd>
{\makebox[\@pnumwidth][\cftpnumalign]}% <search>
{}% <replace>
{}{}% <success><failure>
\makeatother
}{
% Fixed width page numbers (default)
}
\setlength{\cftbeforetoctitleskip}{0cm}
\setlength{\cftbeforeloftitleskip}{0cm}
\setlength{\cftbeforelottitleskip}{0cm}
@@ -322,6 +347,7 @@
\renewcommand \cftchapdotsep{1} % https://tex.stackexchange.com/a/273764
\renewcommand \cftsecdotsep{1} % https://tex.stackexchange.com/a/273764
\renewcommand \cftsubsecdotsep{1} % https://tex.stackexchange.com/a/273764
\renewcommand \cftsubsubsecdotsep{1} % https://tex.stackexchange.com/a/273764
\renewcommand \cftfigdotsep{1.5} % https://tex.stackexchange.com/a/273764
\renewcommand \cfttabdotsep{1.5} % https://tex.stackexchange.com/a/273764
\renewcommand{\cftchapleader}{\normalfont\cftdotfill{\cftsecdotsep}}