交错 ToC 点 (KOMA-Script)

交错 ToC 点 (KOMA-Script)

这个问题说明了我想要实现的目标: 目录中的点就像棋盘上的点

请注意,每行点都是偏移的,从而形成类似中国跳棋棋盘的图案。

但是我尝试过了,但还是没能成功。有没有一种相对简单的方法可以用 KOMA-Script 类来实现这一点?

在此处输入图片描述

答案1

我在 TeXbook 源代码中找到了答案(我希望这不会侵犯版权,因为这些信息是公开的。如果是,我会立即删除我的答案)。我仍在分析它的工作原理并学习 TeX,所以如果有人愿意帮忙解释那就太好了。

\documentclass{scrartcl}

% from TeXbook source: 
%  https://ctan.org/pkg/texbook?lang=en
%   /systems/knuth/dist/tex/texbook.tex

\countdef\counter=255  % define a new counter at register 255
\def\diamondleaders{\global\advance\counter by 1  % increment above counter every time this command is called
    \ifodd\counter \kern-10pt \fi  % says how far away initial dot can be, adds offset to kern (horizontal space) (?)
    \leaders\hbox to 20pt{\ifodd\counter \kern13pt \else\kern3pt \fi  % define a leader, still learning how these work
        .\hss}\hfil}  % hf
    %                ^(distance between dots)   ^  these show the ^ relative displacement between the two ??
    % from toying with the settings, I've found that adjusting 13 and 3 to the same value makes the dots a square grid
    % I assume the 20pt is the spacing between the dots, and the 13 / 3 is some additional displacement if odd of even


\RedeclareSectionCommand[toclinefill=\diamondleaders]{section}% can repeat this for sub, subsub, etc.


\begin{document}    
    \tableofcontents
    \section{Alpha}
    \section{Beta}
    \section{Gamma}
    \section{Delta}
\end{document}

在此处输入图片描述

相关内容