在以下 LaTeX 代码中,我希望环境的引用编号nlpr
作为定理的引用编号出现。我该如何修改环境的定义nlpr
?
\documentclass{article}
\newtheorem{thm}{Theorem}[section]
\newcounter{prnum}[section]
\newenvironment{nlpr}
{
\refstepcounter{prnum}
\begin{description}
\setlength{\itemindent}{-4.5mm}
\item[\arabic{prnum}.]
}
{
\end{description}
}
\begin{document}
\section{First section}
\begin{thm}\label{thm1}
This is the first theorem.
\end{thm}
\begin{nlpr}\label{pro1}
This is the first problem.
\end{nlpr}
From the \ref{thm1}, problem \ref{pro1} is clearly solved.
\end{document}
答案1
\newcounter{<cntr>}[<within>]
<cntr>
每次<within>
执行步骤时都会重置。在您的情况下prnum
,计数器将在每个部分重置。但是,表示不包括计数器section
本身。要包含它(类似于计数器theorem
包含的内容),您应该更改\theprnum
:
\documentclass{article}
\newtheorem{thm}{Theorem}[section]
\newcounter{prnum}[section]
\renewcommand{\theprnum}{\thesection.\arabic{prnum}}% <--------------
\newenvironment{nlpr}{%
\refstepcounter{prnum}%
\begin{description}
\setlength{\itemindent}{-4.5mm}%
\item[\theprnum.]
}{%
\end{description}
}
\begin{document}
\section{First section}
\begin{thm}\label{thm1}
This is the first theorem.
\end{thm}
\begin{nlpr}\label{pro1}
This is the first problem.
\end{nlpr}
From Theorem \ref{thm1}, Problem \ref{pro1} is clearly solved.
\end{document}