열거 환경 내의 그림 캡션

열거 환경 내의 그림 캡션

여기서 처음으로 질문을 받았습니다. \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}

관련 정보