0

I have defined a custom floating environment using newfloat to describe some application scenarios. These scenarios have distinctive and short names, which I would like to use as the "number" of the floating environment instead of a real number. Is there any way to achieve this:

MWE:

\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}

Basically, the caption in this MWE should be "Scenario ABC: ..." and the \autoref should look the same.

languitar
  • 808
  • @ChristianHupfer getting that right is not the real issue. I don't know how to get a custom string as a "number" for the float. – languitar Nov 28 '17 at 11:33
  • It is actually connected, since you must modify the caption setup and the way @currentlabel is defined –  Nov 28 '17 at 11:41
  • @ChristianHupfer if this helps, in my target document I am actually using the combination of hyperref, varioref and cleveref. – languitar Nov 28 '17 at 11:47

1 Answers1

3

You have to pass the desired label somehow. The simplest is to define a new environment that calls the new float type.

\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}

enter image description here

egreg
  • 1,121,712