在章节末尾添加按章节编号的练习

在章节末尾添加按章节编号的练习

我想在章节末尾添加按章节编号的练习(如下图所示)我该怎么做?

在此处输入图片描述

我的代码是

 \documentclass{article}
 \usepackage{makeidx}
 \usepackage{amsmath, amssymb}
 \usepackage{amsfonts}
 \usepackage{stmaryrd}
 \usepackage{tasks}
 \usepackage[ddmmyyyy]{datetime}
 \usepackage[a4paper,left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
 \usepackage{tikz}
 \usepackage{xypic}
 \usepackage{tkz-euclide}
 \usepackage{pgfplots}
 \usepackage{xcolor}
 \usepackage{mwe}

  \usetikzlibrary{calc,angles,positioning,intersections,quotes, arrows, 
  arrows.meta, decorations.markings, patterns, datavisualization}
  \usepgfplotslibrary{fillbetween, polar}
   \pgfplotsset{compat=newest}
   \usepgflibrary{shapes.geometric}
  \pgfplotsset{my style/.append style={axis x line=middle, axis y line=
    middle, xlabel={$x$}, ylabel={$y$}, axis equal }}
  \linespread{1.5}
  \newtheorem{theorem}{Teorem}
  \newtheorem{acknowledgement}[theorem]{Acknowledgement}
  \newtheorem{algorithm}[theorem]{Algorithm}
  \newtheorem{axiom}[theorem]{Axiom}
  \newtheorem{case}[theorem]{Case}
  \newtheorem{claim}[theorem]{Claim}
  \newtheorem{conclusion}[theorem]{Sonu\c{c}}
  \newtheorem{condition}[theorem]{Condition}
  \newtheorem{conjecture}[theorem]{Conjecture}
  \newtheorem{corollary}[theorem]{Sonu\c{c}}
  \newtheorem{criterion}[theorem]{Criterion}
  \newtheorem{definition}[theorem]{Tan\i m}
  \newtheorem{example}[theorem]{\"{O}rnek}

  \newenvironment{proof}[1][Kan\i t]{\noindent\text{#1:} }{$\square$}
  \newenvironment{remark}[1][Not]{\noindent\textbf{#1:} }{}
  \newenvironment{solution}[1][\c{C}\"{o}z\"{u}m]{\noindent\text{#1:} } 
   {}
  \renewcommand{\dateseparator}{.}
  \makeatletter

  \usepackage{enumitem}
  \newlist{exercise}{enumerate}{5}
  \setlist[exercise] 
  {label*=\thesection.\arabic*.,ref=\thesection.\arabic*,before= 
  {\subsection*{Exercises}}}

  \begin{document}


  \section{Section 1}

  \subsection{Subsection 1}

  \begin{exercise}


  \item A

  \item B

  \item C

  \end{exercise}

  \subsection{Subsection 2}

  \begin{exercise}


  \item E

  \item F

  \item G

  \end{exercise}

  \section{Section 2}

  \subsection{Subsection 3}

  \begin{exercise}

  \item H

  \item I

  \item J

  \end{exercise}

  \subsection{Subsection 4}

  \begin{exercise}
  \item K
  \item L

  \item M

  \end{exercise}

  \end{document}

但它产生的并不是我想要的

在此处输入图片描述

答案1

应该做两件事。

(1)添加resume\setlist[exercise]{... 继续在小节之间编号;然后

(2)将每个部分的编号重置为 1(使用\restartlist{exercise})。

A

% !TeX TS-program = pdflatex 
 
\documentclass{article}
\usepackage{makeidx}
\usepackage{amsmath, amssymb}
\usepackage{amsfonts}
\usepackage{stmaryrd}
\usepackage{tasks}
\usepackage[ddmmyyyy]{datetime}
\usepackage[a4paper,left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\usepackage{tikz}
\usepackage{xypic}
\usepackage{tkz-euclide}
\usepackage{pgfplots}
\usepackage{xcolor}
\usepackage{mwe}

\usetikzlibrary{calc,angles,positioning,intersections,quotes, arrows, 
    arrows.meta, decorations.markings, patterns, datavisualization}
\usepgfplotslibrary{fillbetween, polar}
\pgfplotsset{compat=newest}
\usepgflibrary{shapes.geometric}
\pgfplotsset{my style/.append style={axis x line=middle, axis y line=
        middle, xlabel={$x$}, ylabel={$y$}, axis equal }}
\linespread{1.5}
\newtheorem{theorem}{Teorem}
\newtheorem{acknowledgement}[theorem]{Acknowledgement}
\newtheorem{algorithm}[theorem]{Algorithm}
\newtheorem{axiom}[theorem]{Axiom}
\newtheorem{case}[theorem]{Case}
\newtheorem{claim}[theorem]{Claim}
\newtheorem{conclusion}[theorem]{Sonu\c{c}}
\newtheorem{condition}[theorem]{Condition}
\newtheorem{conjecture}[theorem]{Conjecture}
\newtheorem{corollary}[theorem]{Sonu\c{c}}
\newtheorem{criterion}[theorem]{Criterion}
\newtheorem{definition}[theorem]{Tan\i m}
\newtheorem{example}[theorem]{\"{O}rnek}

\newenvironment{proof}[1][Kan\i t]{\noindent\text{#1:} }{$\square$}
\newenvironment{remark}[1][Not]{\noindent\textbf{#1:} }{}
\newenvironment{solution}[1][\c{C}\"{o}z\"{u}m]{\noindent\text{#1:} } 
{}
\renewcommand{\dateseparator}{.}
\makeatletter

\usepackage{enumitem}

\newlist{exercise}{enumerate}{1}
\setlist[exercise] 
{label*=\thesection.\arabic*.,
    ref=\thesection.\arabic*,
    before=     {\subsection*{Exercises}},
    resume % added <<<<<<<<<<<<<<<<<<<<<<
}

\let\oldsection\section
\renewcommand{\section}{\restartlist{exercise}\oldsection} % added <<<<<<<<<<

\begin{document}    

\section{Section 1}
\subsection{Subsection 1}

\begin{exercise}    
    \item A 
    \item B 
    \item C 
\end{exercise}

\subsection{Subsection 2}
\begin{exercise}    
    \item E 
    \item F 
    \item G 
\end{exercise}

\section{Section 2}
\subsection{Subsection 3}

\begin{exercise}
    \item H 
    \item I 
    \item J 
\end{exercise}

\subsection{Subsection 4}
\begin{exercise}
    \item K
    \item L 
    \item M 
\end{exercise}

\end{document}

更新后续问题之后

没有必要定义新的列表。在这个例子中,enumerate使用exercise

% !TeX TS-program = pdflatex 
 
\documentclass{article} 
\usepackage{enumitem}

\setlist[enumerate] 
{label*=\thesection.\arabic*.,
    ref=\thesection.\arabic*,
    before=     {\subsection*{Exercises}},  
    resume, % added <<<<<<<<<<<<<<<<<<<<<<  
}

\let\oldsection\section
\renewcommand{\section}{\restartlist{enumerate}\oldsection} % added <<<<<<<<<<

\begin{document}    

\section{Section 1}
\subsection{Subsection 1}

\begin{enumerate}   
    \item A 
    \item B 
    \item C 
\end{enumerate}

\subsection{Subsection 2}
\begin{enumerate}   
    \item E 
    \item F 
    \item G 
\end{enumerate}

\section{Section 2}
\subsection{Subsection 3}

\begin{enumerate}
    \item H 
    \item I 
    \item J 
\end{enumerate}

\subsection{Subsection 4}
\begin{enumerate}
    \item K
    \item L 
    \item M 
\end{enumerate}

\end{document}

相关内容