对于我的课程(在大学教学),我使用 TeX 文档提供每周的作业和练习,如下所示。
\documentclass{report}
\usepackage{titlesec}
\titlelabel{\thetitle~}
\titleformat{\chapter}[hang]{\color{blue}\Large\bfseries}{Exercise \thechapter\,--\,}{0sp}{\color{blue}}[]
\begin{document}
\chapter{Topic of Week 1}
\section{Task 1}
\section{Task 2}
\chapter{Topic of Week 2}
\section{Task 1}
\section{Task 2}
\end{document}
这将生成如下章节标题练习 1 - 第一周主题。现在我需要一个解决方案来将一个章节拆分为两周,也就是说,它应该导致
- 练习 1A - 第一周主题
- 练习 1B - 第一周剩余内容
因为这些\sections
是我切换到的任务\section
,而且\subsection
整体结构应该保持不变。实际上,我想添加一个新的\chapter{Remainder of Week 1}
,但不要(明显)增加章节计数器。有什么想法吗?
答案1
这是一个仅使用的选项titlesec
:
\documentclass{report}
\usepackage{titlesec,xcolor}
\titlelabel{\thetitle~}
\titleformat{\chapter}
[hang]
{\color{blue}\Large\bfseries}
{Exercise \thechapter\,--\,}
{0sp}
{\color{blue}}
[]
\titleclass{\splitchapter}{top}[\part]
\newcounter{splitchapter}
\renewcommand{\thesplitchapter}{\thechapter\Alph{splitchapter}}
\titleformat{\splitchapter}
[hang]
{\ifnum\value{splitchapter}=1\refstepcounter{chapter}\else\fi
\color{blue}\Large\bfseries}
{Exercise \thesplitchapter\,--\,}
{0sp}
{\color{blue}}
[]
% copied from titlesec doc
\titlespacing*{\splitchapter}{0pt}{50pt}{40pt}
% reset splitchapter counter at each chapter
\AddToHook{cmd/chapter/before}{\setcounter{splitchapter}{0}}
\begin{document}
\chapter{a chapter}
\section{abc}
\section{abc}
\splitchapter{a split chapter}
\section{abc}
\section{abc}
\splitchapter{another split chapter}
\section{abc}
\section{abc}
\chapter{another chapter}
\section{abc}
\section{abc}
\splitchapter{split}
\section{abc}
\end{document}
答案2
我不确定我是否理解你的期望。也许你只是搜索\chapter*
。但也许您想要类似以下内容,这需要更改类:
\documentclass{scrreprt}
\usepackage{color}
\renewcommand*{\chapterformat}{Exercise \thechapter\,--\,}
\addtokomafont{chapter}{\color{blue}}
\DeclareNewSectionCommand[% see the KOMA-Script manual for more information
style=chapter,
level=\chapternumdepth,% same level as chapter
beforeskip:=chapter,% same value as of chapter
afterskip:=chapter,% same value as of chapter
font:=chapter,% same value as of chapter
counterwithin=chapter,% same value as of chapter
]{subchapter}
\DeclareTOCStyleEntry[entryformat:=chapter,indent:=chapter,numwidth:=chapter,numwidth+=.5em,pagenumberformat:=chapter,beforeskip:=chapter]{chapter}{subchapter}% may be useful for the ToC; see the KOMA-Script manual for more information
\renewcommand*{\thesubchapter}{\thechapter\Alph{subchapter}}
\renewcommand*{\subchapterformat}{Exercise \thesubchapter\,--\,}
\begin{document}
\refstepcounter{chapter}% unfortunately needed, if the numbering should not be 1, 1A, 1B but 1A, 1B without a 1 before
\subchapter{Topic of Week 1}
\section{Task 1}
\section{Task 2}
\subchapter{Remainder of Week 1}
\section{Task 3}
\section{Task 4}
\chapter{Topic of Week 2}
\section{Task 1}
\section{Task 2}
\end{document}
但也许你还想使用 1A.1、1A.2、1B.1、1B.2 作为章节编号?在这种情况下,你可以使用如下代码:
\documentclass{report}
\usepackage{color}
\usepackage{titlesec}
\titlelabel{\thetitle~}
\titleformat{\chapter}[hang]{\color{blue}\Large\bfseries}{Exercise \thechapter\,--\,}{0sp}{\color{blue}}[]
\newcounter{realchapter}
\newenvironment{subtopic}{%
\clearpage
\refstepcounter{chapter}%
\setcounter{realchapter}{\value{chapter}}%
\renewcommand{\thechapter}{\therealchapter\Alph{chapter}}%
\setcounter{chapter}{0}%
}{%
\clearpage
}
\begin{document}
\begin{subtopic}
\chapter{Topic of Week 1}
\section{Task 1}
\section{Task 2}
\chapter{Remainder of Week 1}
\section{Task 1}
\section{Task 2}
\end{subtopic}
\chapter{Topic of Week 2}
\section{Task 1}
\section{Task 2}
\end{document}