将当前节号放入类似 theom 的环境名称中

将当前节号放入类似 theom 的环境名称中

以下源连续编号各节中的练习。它成功地为每个练习集添加了一个包含当前节号的目录条目。

问题:我如何才能让每个练习集的名称“EXERCISES FOR SECTION 0”真正显示当前的章节编号?

类定理环境中\thesection的参数部分,并没有获取到实际的当前章节编号。name={EXERCISES FOR SECTION~\thesection}problemscontent

\documentclass{article}

\usepackage{amsthm,thmtools}
%the
\declaretheoremstyle[
    headformat=\NAME\NOTE,
    headfont= \sffamily\bfseries,
    headpunct={\vspace{\topsep}\newline},
    numbered=no,
    spaceabove= 3.25ex plus 1ex minus .2ex,postheadspace=0pt    
]{probs}
%
\declaretheorem[
  name={EXERCISES FOR SECTION~\thesection},
  style=probs,
  preheadhook={\addcontentsline{toc}{subsection}{Exercises for Section~\thesection}}
]{problemscontent}
%
\newenvironment{problemset}
{\problemscontent}
{\endproblemscontent}

\usepackage{enumitem}
%
\newlist{problems}{enumerate}{3}
\setlist[problems,1]{%
    label=\bfseries\sffamily\arabic*.,
    ref={\arabic*},
    before=\leavevmode \vspace{-\dimexpr\baselineskip+\topsep\relax}}

\begin{document}
\tableofcontents

\section{Introduction}

\begin{problemset}
  \begin{problems}[series=probs]
    \item First problem.
    \item Second problem.
  \end{problems}
\end{problemset}

\section{Details}

\begin{problemset}
  \begin{problems}[resume*=probs]
    \item A new exercise.
  \end{problems}
\end{problemset}

\end{document}

练习名称中需要节编号

答案1

如果想扩展,\thesection则在声明定理但在使用时,你必须保护\thesection

\documentclass{article}

\usepackage{amsthm,thmtools}
%the
\declaretheoremstyle[
    headformat=\NAME\NOTE,
    headfont= \sffamily\bfseries,
    headpunct={\vspace{\topsep}\newline},
    numbered=no,
    spaceabove= 3.25ex plus 1ex minus .2ex,postheadspace=0pt    
]{probs}
%
\declaretheorem[
  name={EXERCISES FOR SECTION~\protect\thesection},% CHANGED
  style=probs,
  preheadhook={\addcontentsline{toc}{subsection}{Exercises for Section~\thesection}}
]{problemscontent}
%
\newenvironment{problemset}
{\problemscontent}
{\endproblemscontent}

\usepackage{enumitem}
%
\newlist{problems}{enumerate}{3}
\setlist[problems,1]{%
    label=\bfseries\sffamily\arabic*.,
    ref={\arabic*},
    before=\leavevmode \vspace{-\dimexpr\baselineskip+\topsep\relax}}

\begin{document}
\tableofcontents

\section{Introduction}

\begin{problemset}
  \begin{problems}[series=probs]
    \item First problem.
    \item Second problem.
  \end{problems}
\end{problemset}

\section{Details}

\begin{problemset}
  \begin{problems}[resume*=probs]
    \item A new exercise.
  \end{problems}
\end{problemset}

\end{document}

在此处输入图片描述

然而,我问自己:为什么要使用像定理这样的环境,而不是仅仅problems通过标题进行扩展?

\documentclass{article}

\usepackage{enumitem}
%
\newlist{problems}{enumerate}{3}
\setlist[problems,1]{%
    label=\bfseries\sffamily\arabic*.,
    ref={\arabic*},
    before=\problemsheading}
\newcommand*{\problemsheading}{%
  \subsection*{\sffamily EXERCISES FOR SECTION~\thesection}
  \addcontentsline{toc}{subsection}{Exercises for Section~\thesection}
}
  
\begin{document}
\tableofcontents

\section{Introduction}

\begin{problems}[series=probs]
\item First problem.
\item Second problem.
\end{problems}

\section{Details}

\begin{problems}[resume*=probs]
\item A new exercise.
\end{problems}

\end{document}

在此处输入图片描述

要减小练习标题的大小,您可以用 替换\subsection*\subsubsection*向 中添加字体大小命令\sffamily。或者您可以使用包titlesec来配置子部分的标题。

相关内容