如何為新的計數器樣式定義自己的符號序列?

如何為新的計數器樣式定義自己的符號序列?

我知道我可以更改計數器樣式,如下所示:

\renewcommand\thechapter{\Roman{chapter}}

(上述命令將使章節號以大寫羅馬數字書寫)

然而,根據維基教科書和一個答案這個問題,我只能在阿拉伯文、羅馬文、希臘文和腳註符號中選擇:

  • \arabic1, 2, 3 ...
  • \alph甲、乙、丙…
  • \Alph甲、乙、丙…
  • \roman一、二、三…
  • \Roman一、二、三…
  • \fnsymbol針對腳註;列印一系列符號。

有沒有辦法可以為計數器定義自己的符號序列?

答案1

您可以輕鬆地調整其定義\alph,如下所示latex.ltx

\def\alph#1{\expandafter\@alph\csname c@#1\endcsname}
\def\@alph#1{%
  \ifcase#1\or a\or b\or c\or d\or e\or f\or g\or h\or i\or j\or
   k\or l\or m\or n\or o\or p\or q\or r\or s\or t\or u\or v\or w\or x\or
    y\or z\else\@ctrerr\fi}

這是自訂序列的 MWE。

\documentclass{article}
\makeatletter
\def\mysequence#1{\expandafter\@mysequence\csname c@#1\endcsname}
\def\@mysequence#1{%
  \ifcase#1\or AAA\or BBB\or CCC\else\@ctrerr\fi}
\makeatother
\renewcommand\thesection{\mysequence{section}}
\begin{document}
\section{Section}
\section{Section}
\section{Section}
%\section{Section} % --> LaTeX Error: Counter too large
\end{document}

請注意,如果計數器值太高(在我的範例 4 中),此實作將停止工作。因此請確保定義了足夠的符號。

相關內容