In a document of mine (scrbook class) I have to describe several different scenarios as part of a subsection. I originally used \subsubsection for each which are not numbered with the default setting of secnumdepth. I could change that counter but having something 1.2.3.1 for a scenario would not look good.
A problem is that I can't proper \reference a specific scenario like this because the \label would point to the parent \subsection. Using a enumerate environment isn't really an option here as well.
I would now define a sectioning-like macro \scenario which
- Is formatted like
\subsubsection*of the used class (scrbookin my case). - Starts with
Scenario \thescenario:~, where\thescenariowould be a single integer (1, 2, ...) independent of the parent section numbers. - Can be
\labeled and referenced correctly usinghyperrefs\autoref.
My first approach was the following:
\documentclass{scrbook}
\usepackage{hyperref}
\newcounter{scenario}
\newcommand{\scenarioautorefname}{scenario}
\newcommand{\scenario}[1]{%
\refstepcounter{scenario}%
\subsubsection*{Scenario~\thescenario: #1}%
%\refstepcounter{scenario}%
}%
\begin{document}
\chapter{MWE}
\section{Grandparent}
\subsection{Parent}
\scenario{Foo}\label{sce:foo}
...
\scenario{Bar}\label{sce:bar}
...
In \autoref{sce:foo} ...
\end{document}
This gives me the format of \subsubsection*, but the issue is that it interferes with the \refstepcounter. If I put \refstepcounter{scenario} before it, the scenario number is correct but the \autoref will use subsubsection not scenario for the reference. If I put it at the end of the macro the reference name is correct but the number is off by one, i.e. one to low. Setting the number initially to 1 gives my the correct number in the \scenario line and the correct name in \autoref but there the number is off by one again, this time one to high.
How can I define such a sectioning-like macro? I personally wouldn't mind using Koma-Script macros to do so, but would welcome a class-independent solution more.
hyperrefpackage to make your code compilable. – Gonzalo Medina May 3 '11 at 15:48