我正在尝试引用包中的newenvironment
使用。以下是演示我正在尝试执行的操作的 MWE。cref
cleveref
\documentclass{article}
\usepackage{cleveref}
% define a newenvironment
\newcounter{projectCounter}
\setcounter{projectCounter}{0}
\newenvironment{project}[1]{\par\addvspace{1\baselineskip minus
20pt}\refstepcounter{projectCounter}{\bf\large Project
\arabic{projectCounter}: #1}\newline}{\par\addvspace{1\baselineskip minus 20pt}}
% define another newenvironment
\newcounter{subprojectCounter}
\setcounter{subprojectCounter}{0}
\newenvironment{subproject}[1]{\par\addvspace{1\baselineskip minus
20pt}\refstepcounter{subprojectCounter}{\bf\large Sub-project
\arabic{projectCounter}.\arabic{subprojectCounter}: #1}\newline}{\par\addvspace{1\baselineskip minus 20pt}}
% define a nested new environment
\newenvironment{projectStack}{\begin{project}\begin{subproject}}{\end{subproject}\end{project}}
% give names to the cref calls.
\crefname{project}{ project }{ projects }
\Crefname{project}{ Project }{ Projects }
\crefname{subproject}{ sub-project }{ sub-projects }
\Crefname{subproject}{ Sub-project }{ Sub-projects }
\begin{document}
This is a document that talks about sub-projects within projects.
\begin{project}{A}
Some information related to the project.
% begin a sub-project
\begin{subproject}{AA}
Some information related to the subproject.
\label{subproj:AA}
\end{subproject}
% begin another sub-project
\begin{subproject}{BB}
Some information related to the subproject.
\label{subproj:BB}
\end{subproject}
% begin a sub-project
\begin{subproject}{CC}
Some information related to the subproject.
\label{subproj:CC}
\end{subproject}
\label{proj:A}
\end{project}
Now let me try to refer to the projects, like so, \cref{proj:A}, and to
the subprojects, like so, \cref{subproj:AA,subproj:BB,subproj:CC}.
\end{document}
这里,我定义了project
和subproject
newenvironment
,然后尝试使用函数引用它们cleveref
cref
。然而,这似乎不起作用,尽管我使用了crefname
和Crefname
函数。
任何有助于解决此问题的帮助都将非常有帮助。
答案1
\crefname
诸如此类的应该指的是计数器,而不是环境,所以你应该说
\crefname{projectCounter}{project}{projects}
这是一个完整的示例,其中对您的宏进行了一些更正。
\documentclass{article}
\usepackage{cleveref}
% define a newenvironment
\newcounter{projectCounter}
\newenvironment{project}[1]
{\par\addvspace{1\baselineskip minus .3\baselineskip}%
\refstepcounter{projectCounter}%
\noindent{\bfseries\large Project \theprojectCounter: #1}\newline}
{\par\addvspace{1\baselineskip minus .3\baselineskip}}
% define another newenvironment
\newcounter{subprojectCounter}[projectCounter]
\renewcommand\thesubprojectCounter{\theprojectCounter.\arabic{subprojectCounter}}
\newenvironment{subproject}[1]
{\par\addvspace{1\baselineskip minus .3\baselineskip}%
\refstepcounter{subprojectCounter}%
\noindent{\bfseries\large Sub-project \thesubprojectCounter: #1}\newline}
{\par\addvspace{1\baselineskip minus .3\baselineskip}}
% define a nested new environment
\newenvironment{projectStack}
{\project\subproject}
{\endsubproject\endproject}
% give names to the cref calls.
\crefname{projectCounter}{project}{projects}
\Crefname{projectCounter}{Project}{Projects}
\crefname{subprojectCounter}{sub-project}{sub-projects}
\Crefname{subprojectCounter}{Sub-project}{Sub-projects}
\begin{document}
This is a document that talks about sub-projects within projects.
\begin{project}{A}
Some information related to the project.
% begin a sub-project
\begin{subproject}{AA}
Some information related to the subproject.
\label{subproj:AA}
\end{subproject}
% begin another sub-project
\begin{subproject}{BB}
Some information related to the subproject.
\label{subproj:BB}
\end{subproject}
% begin a sub-project
\begin{subproject}{CC}
Some information related to the subproject.
\label{subproj:CC}
\end{subproject}
\label{proj:A}
\end{project}
Now let me try to refer to the projects, like so, \cref{proj:A}, and to
the subprojects, like so, \cref{subproj:AA,subproj:BB,subproj:CC}.
\end{document}