
我想用縮寫替換零件號碼。例如,關於以下 MWE 的部分代數,我希望將ALG.1
其稱為第一章I.1
(對於所考慮部分的所有章節都相同)。
理想情況下,縮寫ALG
可以是命令的可選參數\part
。
微量元素:
\documentclass[oneside]{scrbook}
%reset chapter for each part
\makeatletter
\@addtoreset{chapter}{part}
\makeatother
\renewcommand{\thechapter}{\thepart\arabic{chapter}}
\begin{document}
\part{Algebra} %\part[ALG]{Algebra} ?
\chapter{Chap 1}
\part{Analysis}
\chapter{Chap 1}
\part{Geometry}
\chapter{Chap 1}
\end{document}
答案1
這是一個簡單的解決方案,在指令\acropart
之後使用一個指令\part
:
\documentclass[oneside]{scrbook}
\counterwithin*{chapter}{part}
\makeatletter
\DeclareRobustCommand\acropart[1]{\gdef\@acropart{#1}}
\renewcommand{\thechapter}{\@acropart.~\arabic{chapter}}
\makeatother
\makeatother
\begin{document}
\part{Algebra} %\part[ALG]{Algebra} ?
\acropart{ALG}
\chapter{Chapter the first}
\chapter{Chapter the second}
\part{Analysis}
\acropart{ANAL}
\chapter{Chapter the first}
\part{Geometry}
\acropart{GEOM}
\chapter{Chapter the first}
\end{document}
答案2
問題中的 MWE 已經包含 的重新定義\thechapter
。這可以透過\thepart
用包含所需縮寫的新巨集替換零件計數器來進一步自訂。
\part
要使用舊定義的可選參數進行設置,\part
可以將其存儲在另一個宏中,例如\oldpart
,然後\part
可以重新定義以接受可選參數,將其存儲在宏中,然後調用\oldpart
將處理預設參數的宏,如同\def 中的可選參數。可選參數的預設值為\thepart
,以允許沒有標籤的零件使用羅馬零件編號進行編號。
列印目錄時,章節標籤不適合預設寬度,可以使用 解決此問題\RedeclareSectionCommand
。
微量元素:
\documentclass[oneside]{scrbook}
\RedeclareSectionCommand[
tocnumwidth=1.5cm
]{chapter}
\let\oldpart\part
\renewcommand\part[1][\thepart]{\def\partacr{#1}\oldpart}
%reset chapter for each part
\makeatletter
\@addtoreset{chapter}{part}
\makeatother
\renewcommand{\thechapter}{\partacr.\arabic{chapter}}
\begin{document}
\tableofcontents
\part[ALG]{Algebra}
\chapter{Chap 1}
\chapter{Chap 2}
\part{Geometry}
\chapter{Chap 1}
\chapter{Chap 2}
\end{document}
結果:
答案3
像這樣?
\documentclass[oneside]{scrbook}
%reset chapter for each part
\makeatletter
\@addtoreset{chapter}{part}
\makeatother
\newcommand{\prt}[2]{\part{#2}
\renewcommand{\thechapter}{#1\arabic{chapter}}}
\usepackage{tocloft}
\renewcommand\cftchapnumwidth{1.2cm} %<-- For tableofcontents
\begin{document}
\tableofcontents
\prt{ALG}{Algebra} %\part[ALG]{Algebra} ?
\chapter{Chap 1}
\prt{ANA}{Analysis}
\chapter{Chap 1}
\prt{GEO}{Geometry}
\chapter{Chap 1}
\end{document}