我正在尝试申请leandriis 的绝妙食谱使用生成子方案chemmacros
,cleveref
, 和subcaption
包。
在以下示例中,我做错了什么?方案编号从 0 开始,但我希望它们从 1 开始。我确信我的错误很明显,但我就是看不到。感谢您提供的任何帮助。
\documentclass[oneside,11pt]{book}
\usepackage[semibold,tt=false]{libertine}
\usepackage{libertinust1math}
\usepackage[font={sf,small},labelsep=quad,labelfont=sc]{caption}
\usepackage[subrefformat=parens]{subcaption}
\usepackage[
expansion = false ,
tracking = smallcaps ,
letterspace = 40 ,
]{microtype}
\usepackage{booktabs}
\usepackage{acro}
\acsetup{
barriers/use, barriers/reset,
use-id-as-short,
}
\usepackage{chemformula}
\setchemformula{charge-hshift=.5pt}
\usepackage{chemmacros}
\usechemmodule{scheme}
\usepackage{graphicx}
\usepackage[titles]{tocloft}
\setlength{\cftfignumwidth}{2.9em}
\setlength{\cfttabnumwidth}{2.9em}
\AtEndPreamble{\DeclareCaptionSubType*{scheme}\counterwithin{scheme}{chapter}\renewcommand\thesubscheme{\thescheme\alph{subscheme}}}
\usepackage{xpatch}
\makeatletter
\xapptocmd{\@chapter}{\addtocontents{los}{\protect\addvspace{10\p@}}}{}{}
\makeatother
\usepackage[capitalize]{cleveref}
\crefformat{subscheme}{\schemename~#2#1#3}
\begin{document}
\tableofcontents
\addcontentsline{toc}{chapter}{\listfigurename}
\listoffigures
\addcontentsline{toc}{chapter}{\listschemename}
\listofschemes
% Example figure
\begin{figure}[!h]
\centering
\includegraphics[width=0.02\textwidth]{example-image}
\caption{Caption of figure in first chapter.}\label{fig:firstfig}
\end{figure}
% Example subfigure
\begin{figure}[!h]
\centering
\begin{subfigure}{0.03\textwidth}
\includegraphics[width=\textwidth]{example-image-a}%
\phantomsubcaption\label{fig:secondfig:a}
\end{subfigure}%
\begin{subfigure}{0.03\textwidth}
\includegraphics[width=\textwidth]{example-image-b}%
\phantomsubcaption\label{fig:secondfig:b}
\end{subfigure}%
\caption{Caption of second figure.
Part \subref{fig:secondfig:a} and part \subref{fig:secondfig:b}.}\label{fig:secondfig}
\end{figure}
% Example scheme
\begin{scheme}[!h]
\centering
\includegraphics[width=0.02\textwidth]{example-image-a}
\caption{Caption of first scheme.}\label{sch:firstscheme}
\end{scheme}
% Example subscheme
\begin{scheme}[!h]
\centering
\begin{subscheme}{0.03\textwidth}
\includegraphics[width=\textwidth]{example-image-a}%
\phantomsubcaption\label{sch:thirdscheme:a}
\end{subscheme}%
\begin{subscheme}{0.03\textwidth}
\includegraphics[width=\textwidth]{example-image-b}%
\phantomsubcaption\label{sch:thirdscheme:b}
\end{subscheme}%
\caption{Caption of third scheme.
Part \subref{sch:thirdscheme:a} and part \subref{sch:thirdscheme:a}.}\label{sch:thirdscheme}
\end{scheme}
Refer to \cref{fig:firstfig} using cleveref package.
Refer to \cref{sch:firstscheme}.
Refer to \cref{fig:secondfig}, \cref{fig:secondfig:a}, and \cref{fig:secondfig:b}.
Finally refer to \cref{sch:thirdscheme}, \cref{sch:thirdscheme:a}, and \cref{sch:thirdscheme:b}.
\end{document}
答案1
指令\counterwithin{scheme}{chapter}
告诉 LaTeX
scheme
每次计数器都会重置\chapter
;- 计数器的表示形式为“章节编号”。“方案编号”;用更专业的术语来说,
\thescheme
被重新定义为\thechapter.\arabic{scheme}
。
如果您没有\chapter
命令,计数器chapter
将保持在 0,因此第一个scheme
标题将编号为 0.1,第二个标题将编号为 0.2,依此类推。
你需要 \chapter
踏上柜台chapter
。