如何设置这样的计数器?

如何设置这样的计数器?

我想设置一个像图片一样的计数器

在此处输入图片描述

我只能做

\documentclass[a4paper, 12pt]{article}
\usepackage{fouriernc}
\usepackage{amsmath}\usepackage[thmmarks,standard,thref]{ntheorem}
\pagestyle{empty}

\theoremseparator{.}
\theorembodyfont{\upshape}
%\theorembodyfont{\normalfont}
\newtheorem{pro}{Problem}
\begin{document}
\begin{pro}
This is a Problem. 
\end{pro}
\begin{pro}
This is a Problem. 
\end{pro}
\begin{pro}
This is a Problem. \end{pro}
\begin{pro}
This is a Problem.
\end{pro}
\begin{pro}
This is a Problem.
\end{pro}
\begin{pro}
This is a Problem.
\end{pro}
\end{document} 

如何设置像这个图片这样的计数器?

答案1

在此处输入图片描述

\documentclass[a4paper, 12pt]{article}
\usepackage{fouriernc}
\usepackage{amsmath}\usepackage[thmmarks,standard,thref]{ntheorem}
\pagestyle{empty}

\theoremseparator{.}
\theorembodyfont{\upshape}
%\theorembodyfont{\normalfont}
\newtheorem{pro}{Problem}
\newcounter{probtype}
\renewcommand\theprobtype{\alph{probtype}}
\renewcommand\thepro{\arabic{pro}\theprobtype}

\begin{document}
\begin{pro}
This is a Problem. 
\end{pro}
\begin{pro}
This is a Problem. 
\end{pro}
\setcounter{probtype}{1}
\begin{pro}
This is a Problem. \end{pro}
\begin{pro}
This is a Problem.
\end{pro}
\setcounter{probtype}{2}
\begin{pro}
This is a Problem.
\end{pro}
\setcounter{probtype}{0}
\begin{pro}
This is a Problem.
\end{pro}
\end{document} 

答案2

我确信我从聊天室的 egreg 那里学到了这个技巧。下面是我的解决方案(我会尝试想出一个更复杂的解决方案,但我不保证)。请注意,如果您还希望使用\label-\ref机制,那么这种方法不太适用。

\documentclass{amsart} 
\usepackage{amsthm}
\theoremstyle{plain}
\newtheorem*{proaux}{Problem \protect\pronumber}
\newenvironment{pro}[1]{\def\pronumber{#1}\proaux}{\endproaux}
\begin{document}
\begin{pro}{1}
  This is a problem!
\end{pro}
\begin{pro}{2a}
  This is a problem!
\end{pro}
\begin{pro}{3a}
  This is a problem!
\end{pro}
\begin{pro}{2b}
  This is a problem!
\end{pro}
\begin{pro}{3b}\label{pro:3b}
  This is a problem!
\end{pro}
\begin{pro}{4}
  This is a problem!
\end{pro}
In problem \ref{pro:3b}, you should have noticed that 
\end{document}

职业.png

答案3

这是一个不同的解决方案pgfkeys

一罐:

  • 开始一个子问题(例如start sub problem打印这个);2a
  • 继续解决子问题continue sub problem2b例如,打印此内容)。

这两个键应该用于“连续”子问题。如果子问题不是“连续”的:

  • start custom sub problem再次开始列表,即打印6a
  • continue sub problem list继续列表,即打印7a
  • continue custom sub problem改变子问题,即打印6b

一个例子:

\documentclass[a4paper, 12pt]{article}
\usepackage{fouriernc}
\usepackage{amsmath}
\usepackage[thmmarks,standard,thref]{ntheorem}
\usepackage{pgfkeys}
\pagestyle{empty}

\theoremseparator{.}
\theorembodyfont{\upshape}
\newtheorem{prob}{Problem}

\newcounter{subproblem}
\newcounter{auxproblem}

\pgfkeys{/theorem prob/.cd,
  start sub problem/.code={%
    \setcounter{subproblem}{1}
    \renewcommand{\theprob}{\arabic{prob}\alph{subproblem}}
  },
  continue sub problem/.code={
    \stepcounter{subproblem}
    \addtocounter{prob}{-1}
    \renewcommand{\theprob}{\arabic{prob}\alph{subproblem}}
  },
  start custom sub problem/.code={
    \setcounter{subproblem}{1}
    \renewcommand{\theprob}{\arabic{prob}\alph{subproblem}}
    \setcounter{auxproblem}{\value{prob}}
  },
  continue sub problem list/.code={    
    \renewcommand{\theprob}{\arabic{prob}\alph{subproblem}}
  },
  continue custom sub problem/.code={
    \setcounter{prob}{\value{auxproblem}}
    \stepcounter{subproblem}
    \renewcommand{\theprob}{\arabic{prob}\alph{subproblem}}
  },
}

\newenvironment{pro}[1][]{%
  \pgfkeys{/theorem prob/.cd,#1}
  \begin{prob}
}{%
  \end{prob}
}


\begin{document}
\begin{pro}
This is a Problem. 
\end{pro}
\begin{pro}
This is a Problem. 
\end{pro}
\begin{pro}
This is a Problem. 
\end{pro}
\begin{pro}[start sub problem]
This is a Problem.
\end{pro}
\begin{pro}[continue sub problem]\label{pro:4b}
This is a Problem.
\end{pro}
\begin{pro}[continue sub problem]
This is a Problem.
\end{pro}
\begin{pro}
This is a Problem.
\end{pro}
\begin{pro}[start custom sub problem]
This is a Problem.
\end{pro}
\begin{pro}[continue sub problem list]
This is a Problem.
\end{pro}
\begin{pro}[continue sub problem list]
This is a Problem.
\end{pro}
\begin{pro}[continue custom sub problem]
This is a Problem.
\end{pro}
\begin{pro}[continue sub problem list]
This is a Problem.
\end{pro}
\begin{pro}[continue sub problem list]\label{pro:8b}
This is a Problem.
\end{pro}
\begin{pro}[continue custom sub problem]
This is a Problem.
\end{pro}
\begin{pro}[continue sub problem list]
This is a Problem.
\end{pro}
\begin{pro}[continue sub problem list]
This is a Problem.
\end{pro}
\begin{pro}
This is a Problem.
\end{pro}
\begin{pro}
This is a Problem which refers to problem~\ref{pro:4b} and to problem~\ref{pro:8b}.
\end{pro}
\end{document}

结果:

在此处输入图片描述

相关内容