\section*
我的文档 (documentclass) 中有未编号的节 ( ) article
,但我需要在节内有编号的图表、表格和脚注。由于节未编号,常规解决方案(如\counterwithin{figure}{section}
或)\@addtoreset{footnote}{section}
不起作用。您能帮助我吗?
\documentclass[11pt,a5paper,oneside]{article}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\begin{document}
\section*{section A}
\addcontentsline{toc}{section}{Section A}
Lorem ipsum dolor sit amet.\footnote{Ut enim ad minim veniam.}
\section*{section B}
\addcontentsline{toc}{section}{Section B}
Duis aute irure dolor in reprehenderit in voluptate velit.\footnote{Excepteur sint occaecat cupidatat non proident.} Sed ut perspiciatis unde omnis iste natus error. \footnote{Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit.}
\end{document}
我需要将 B 部分中的脚注编号为脚注 1 和脚注 2,而不是像现在这样编号为脚注 2 和脚注 3。
答案1
你可以试试\stepcounter{section}\addtocounter{section}{-1}
\documentclass[11pt,a5paper,oneside]{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\makeatletter
\@addtoreset{footnote}{section}
\makeatother
\begin{document}
\section*{section A}
\addcontentsline{toc}{section}{Section A}
Lorem ipsum dolor sit amet.\footnote{Ut enim ad minim veniam.}
\section*{section B}
\stepcounter{section}\addtocounter{section}{-1}
\addcontentsline{toc}{section}{Section B}
Duis aute irure dolor in reprehenderit in voluptate velit. \footnote{Excep}
\end{document}
答案2
footnote
每次使用 时重置计数器\section
,无论是\section
或\section*
:
\documentclass{article}
\usepackage{xparse}
\let\oldsection\section
\RenewDocumentCommand{\section}{s o m}{%
\setcounter{footnote}{0}% Reset footnote counter
\IfBooleanTF{#1}
{\oldsection*{#3}% \section*[..]{...}
\addcontentsline{toc}{section}{#3}}
{\IfNoValueTF{#2}
{\oldsection{#3}}% \section{...}
{\oldsection[#2]{#3}}}% \section[..]{...}
}
\let\oldtableofcontents\tableofcontents
\renewcommand{\tableofcontents}{{%
\let\section\oldsection
\oldtableofcontents
}}
\begin{document}
\tableofcontents
\section*{section A}
Lorem ipsum dolor sit amet.\footnote{Ut enim ad minim veniam.}
\section*{section B}
Duis aute irure dolor in reprehenderit in voluptate velit.\footnote{Excepteur sint occaecat cupidatat non proident.}
Sed ut perspiciatis unde omnis iste natus error.\footnote{Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit.}
\end{document}