
\setcounter{secnumdepth}{0}
나는 번호가 없는 섹션(예: )과 번호가 매겨진 그림, 섹션 내에 번호가 매겨진 그림이 있는 문서를 작성하려고 합니다 . 같이 일할 secnumdepth
수도 없고 chngcntr
일할 수도 없습니다. 내가 얻을 수 있는 최고는 다음과 같습니다.
\documentclass{article}
\usepackage{chngcntr}
\counterwithin*{figure}{section}
%\setcounter{secnumdepth}{0}
\begin{document}
\section{Section the First }
\begin{figure}[h]
\centering
\caption{Figure A}
\end{figure}
\begin{figure}[h]
\centering
\caption{Figure B}
\end{figure}
\section{Section the Second}
\begin{figure}[h]
\centering
\caption{Figure C}
\end{figure}
\end{document}
이렇게 하면 그림 번호가 올바르게 표시되지만 섹션 번호가 있습니다.
줄의 주석 처리를 제거하면 \setcounter{secnumdepth}{0}
원하는 대로 섹션의 번호가 매겨지지 않지만 수치는 이제 다시 'counterwithout'이 됩니다.
번호가 매겨지지 않은 섹션에서 섹션별 그림 번호 매기기를 어떻게 얻나요?
답변1
카운터가 리셋되지 않는 이유는 공통 \@sect
코드에 있습니다. (참조 latex.ltx
)
\def\@sect#1#2#3#4#5#6[#7]#8{%
\ifnum #2>\c@secnumdepth
\let\@svsec\@empty
\else
\refstepcounter{#1}%
\protected@edef\@svsec{\@seccntformat{#1}\relax}%
\fi
....
코드는 섹션 수준( #2
)이 값보다 큰지 테스트합니다 secnumdepth
. 그렇지 않은 경우 섹션 카운터가 다시 시작되고 카운터 재설정 목록의 다른 모든 카운터도 재설정됩니다.
그러나 카운터가 재설정되지 않으면 \counterwithout
여기서는 어쨌든 쓸모가 없습니다( \counterwithout*
또는 \counterwithout
사용 여부에 관계 없음).
한 가지 가능성은 숫자 카운터를 자동으로 0으로 강제 설정하는 것일 수 있지만 \section
이 방법도 함께 사용됩니다 \section*
. 그러나 나는 이것이 실제로 문제가 아니라고 생각합니다.
\documentclass{article}
%\usepackage{chngcntr}
\usepackage{xpatch}
\setcounter{secnumdepth}{0}
%\counterwithin*{figure}{section} Not needed any longer
\xpretocmd{\section}{\setcounter{figure}{0}}{}{} % Prepend the \section code with a figure counter reset.
\begin{document}
\section{Section the First }
\begin{figure}[h]
\centering
\caption{Figure A}
\end{figure}
\begin{figure}[h]
\centering
\caption{Figure B}
\end{figure}
\section{Section the Second}
\begin{figure}[h]
\centering
\caption{Figure C}
\end{figure}
\end{document}