
Мой первый вопрос здесь. Я хочу нумерацию цифр на основе перечисляемого числа, что-то вроде того, \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}