我定义了一个自定义浮动环境,用来newfloat
描述一些应用场景。这些场景有独特而简短的名称,我想用它们作为浮动环境的“编号”,而不是实数。有什么办法可以实现这一点:
梅威瑟:
\documentclass{article}
\usepackage{hyperref}
\usepackage{newfloat}
\DeclareFloatingEnvironment[name=Scenario,within=none]{scenario}
\begin{document}
\begin{scenario}
\center
This is a scenario description text
\caption{This is scenario ABC\@. Should start with Scenario~ABC.}
\label{scenario:abc}
\end{scenario}
Here I want to reference \autoref{scenario:abc} as Scenario~ABC\@.
\end{document}
基本上,这个 MWE 中的标题应该是“场景 ABC:......”并且应该\autoref
看起来相同。
答案1
您必须以某种方式传递所需的标签。最简单的方法是定义一个调用新浮点类型的新环境。
\documentclass{article}
\usepackage{newfloat}
\usepackage{hyperref}
\usepackage{cleveref}
\DeclareFloatingEnvironment[name=Scenario]{scenarioinner}
\newenvironment{scenario}[1]
{\renewcommand\thescenarioinner{#1}%
\scenarioinner}
{\endscenarioinner}
\crefname{scenarioinner}{Scenario}{Scenarios}
\begin{document}
\begin{scenario}{ABC}
\centering
This is a scenario description text
\caption{This is scenario ABC\@. Should start with Scenario~ABC.}
\label{scenario:abc}
\end{scenario}
Here I want to reference \autoref{scenario:abc} as Scenario~ABC\@.
Here I want to reference \cref{scenario:abc} as Scenario~ABC\@.
\end{document}