枚舉環境中的圖標題

枚舉環境中的圖標題

我的第一個問題在這裡。我想要基於枚舉數字對數字進行編號,有點像是\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在環境開始時將數字計數器的原始值保存在 this 中

\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}

相關內容