섹션별 그림 번호 매기기 - 각 섹션마다 카운터 재설정

섹션별 그림 번호 매기기 - 각 섹션마다 카운터 재설정

내 기사 클래스 문서에 그림 번호 매기기와 같은 책을 만들고 싶습니다. MWE:

\documentclass[11pt,a4paper]{article}
\usepackage{graphicx}

% optionally - this creates: Figure 1.1 ... Figure 2.2
%\renewcommand{\thefigure}{\arabic{section}.\arabic{figure}}

\begin{document}

\section{first section}

\begin{figure}[h]
  \centering
    \includegraphics[width=\textwidth]{1.png}
    \caption{figure 1.1} % should be 1.1
\end{figure}

\section{second section}

\begin{figure}[h]
  \centering
    \includegraphics[width=\textwidth]{1.png}
    \caption{figure 2.1} % should be 2.1 - actually is 2 or 2.2 with optional code
\end{figure}

\end{document}

각 섹션에서 수동으로 카운터를 재설정하고 싶지 않습니다.

답변1

이는 \numberwithin다음을 사용하여 쉽게 달성할 수 있습니다.amsmath 패키지.

\documentclass[11pt,a4paper]{article}
\usepackage{graphicx}
\usepackage{amsmath}
\numberwithin{figure}{section}

\begin{document}
\section{first section}

\begin{figure}[h]
  \centering
    \rule{4cm}{4cm}  % replace with image
    \caption{figure 1.1} 
\end{figure}

\section{second section}

\begin{figure}[h]
  \centering
    \rule{4cm}{4cm}  % replace with image
    \caption{figure 2.1} 
\end{figure}
\end{document}

캡션

관련 정보