这是我的第一个问题。我想要基于枚举数字对数字进行编号,有点像\numberwithin{figure}{section}
枚举环境。
示例代码:
\documentclass[10pt,a4paper]{report}
\usepackage{graphicx}
\renewcommand\labelenumi{Q\theenumi.}
\begin{document}
\begin{enumerate}
\item
\begin{enumerate}
\item Question 1 Part (a)
\item Question 1 Part (b)
\begin{figure}[h]
\centering
\includegraphics[width=0.2\linewidth]{imageQ1b}
\caption[Figure Q1(b)]{The caption should be appear as Figure Q1(b) instead of Figure 1: }
\end{figure}
\item Question 1 Part (c)
\begin{figure}[h]
\centering
\includegraphics[width=0.2\linewidth]{imageQ1c}
\caption{The caption should be appear as Figure Q1(c) instead of Figure 2: }
\end{figure}
\end{enumerate}
\item
\begin{enumerate}
\item Question 2 Part(a)
\begin{figure}[h]
\centering
\includegraphics[width=0.2\linewidth]{imageQ2a}
\caption{The caption appear as Figure Q2(a) instead of Figure 3: }
\end{figure}
\item Question 2 Part(b)
\end{enumerate}
\end{enumerate}
\end{document}
谢谢!
答案1
原则上,这只是重新定义图号的印刷表示,例如
\renewcommand{\thefigure}{Q\theenumi(\theenumii)}
(假设每个秒级枚举项只有一个数字,因此的实际值figure
无关紧要)。但是,如果您的文档中的其他地方有数字,您将得到奇怪的编号。因此,首先应在开始时应用此更改enumerate
。
但是,现在其他数字(外部)的数字enumerate
跳过了一些值。解决这个问题的一种方法是定义一个新的计数器
\newcounter{curfigure}
enumerate
在环境开始时将图形计数器的原始值保存在此
\setcounter{curfigure}{\value{figure}}
然后通过相应的方法在最后恢复它\setcounter{figure}{\value{curfigure}}
。
有交叉引用
由于您不希望图形浮动,因此您应该使用center
环境和\captionof{figure}{....}
来自caption
包的元素。
宽图形数字意味着图形列表中的标签与标准设置中的文本重叠report
,因此在下面的代码中我也对其进行了调整。
\documentclass[10pt,a4paper]{report}
\usepackage{graphicx,caption}
\renewcommand\labelenumi{Q\theenumi.}
\newcounter{curfigure}
\makeatletter
\renewcommand{\l@figure}{\@dottedtocline{1}{1.5em}{3em}}
\makeatother
\begin{document}
\listoffigures
\clearpage
\begin{figure}
\centering
Test figure.
\caption{Test figure.}
\label{fig:test}
\end{figure}
\begin{enumerate}
\setcounter{curfigure}{\value{figure}}
\renewcommand{\thefigure}{Q\theenumi(\theenumii)}
\item
\begin{enumerate}
\item Question 1 Part (a)
\item Question 1 Part (b)
\begin{center}
\centering
\includegraphics[width=0.2\linewidth]{example-image-a}
\captionof{figure}{The caption appears as Figure
Q1(b): instead of Figure 1:}\label{fig:1b}
\end{center}
\item Question 1 Part (c)
\begin{center}
\centering
\includegraphics[width=0.2\linewidth]{example-image-b}
\captionof{figure}{The caption appears as Figure Q1(c): instead
of Figure 2:}\label{fig:1c}
\end{center}
\end{enumerate}
\item
\begin{enumerate}
\item Question 2 Part(a)
\begin{center}
\centering
\includegraphics[width=0.2\linewidth]{example-image-a}
\captionof{figure}{The caption appears Figure Q2(a): instead of
Figure 3:}\label{fig:2a}
\end{center}
\item Question 2 Part(b)
\end{enumerate}
\end{enumerate}
\setcounter{figure}{\value{curfigure}}
\begin{figure}
\centering
Test figure two.
\caption{Test figure two.}
\label{fig:test-2}
\end{figure}
\begin{figure}
\centering
Test figure three.
\caption{Test figure three.}
\label{fig:test-3}
\end{figure}
The figures in the questions are \ref{fig:1b}, \ref{fig:1c}
and~\ref{fig:2a}.
The other figures are \ref{fig:test}, \ref{fig:test-2}
and~\ref{fig:test-3}.
\end{document}