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.
\subsubsectionaround. My goal is to define a new sectioning command which inherits its format. – Martin Scharrer May 03 '11 at 16:26\renewcommand\thesubsubsection{\arabic{subsubsection}}is redundant, because this redefinition is already done by the non-starred version of\counterwithout. – lockstep May 03 '11 at 16:31\subsubsection. @lockstep: you're right. Anyway, I changed my code to satisfy the requirement in Martin's comment. – Gonzalo Medina May 03 '11 at 16:45\renewcommand{\thescenario}{\arabic{scenario}}seems to be redundant. – lockstep May 03 '11 at 16:46\subsubsectiondirectly, but must be stated explicitly. – Martin Scharrer May 03 '11 at 16:48hyperrefI figured to use\def\toclevel@scenario{4}which seems to do it. – Martin Scharrer May 06 '11 at 14:46\tocdepthremoves it? – Martin Scharrer Jun 16 '11 at 13:01\l@scenariomacro must be defined, e.g. to\@dottedtocline {3}{3.8em}{3.2em}(taken from subsubsection) to draw the dotted line if thetocdepthis not lower than the first argument (here: 3). – Martin Scharrer Jun 16 '11 at 13:13\toclevel@scenarioand\l@scenariomacros from my comments to the answer, so that it is complete and more useful for other people. Thanks again. – Martin Scharrer Jun 16 '11 at 13:19@Marwould work, but I would prefer@Martin:-). However, you need more letters if there are more than two people in that comment thread which names start withMar. – Martin Scharrer Jun 16 '11 at 13:34