
ここでの質問は初めてです。enumerate 番号に基づいて数字に番号を付けたいのですが、\numberwithin{figure}{section}
enumerate 環境の場合と似ています。
サンプルコード:
\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)}
(第 2 レベルの列挙項目ごとに 1 つの数字しかないと仮定すると、 の実際の値figure
は無関係です)。ただし、ドキュメント内の他の場所に数字がある場合は、それらの番号付けがおかしくなります。したがって、まずこの変更は の先頭にのみ適用する必要がありますenumerate
。
しかし、他の数字(外側)の数は、enumerate
いくつかの値を飛び越えてしまいます。これを回避する方法の1つは、新しいカウンタを定義することです。
\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}