![使用自定义文本作为 newfloat 环境的计数器](https://linux22.com/image/366274/%E4%BD%BF%E7%94%A8%E8%87%AA%E5%AE%9A%E4%B9%89%E6%96%87%E6%9C%AC%E4%BD%9C%E4%B8%BA%20newfloat%20%E7%8E%AF%E5%A2%83%E7%9A%84%E8%AE%A1%E6%95%B0%E5%99%A8.png)
我定义了一个自定义浮动环境,用来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}