0

I adapted this answer to make a custom section I need. My intention is that it looks something like the second heading from this image:

desired_output

So the numbering must be made using (\Alph) and it must be independent from the section/subsection. The counter should restart at each subsection.

Here's a MWE with my attempt to achieve the heading I need:

\documentclass{article}
\usepackage{titlesec}
    %%% seccion para estatica comparativa
    \titleclass{\scenario}{straight}[\subsection]
    \newcounter{scenario}[subsection]
    \titleformat{\scenario}
      {\scshape}{}{0em}{(\thescenario)~}
    \titlespacing*{\scenario}{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}
    \renewcommand*{\thescenario}{\Alph{scenario}}
    \newcommand{\scenarioautorefname}{scenario}

\begin{document}
\setcounter{tocdepth}{1}
\tableofcontents

\section{First section}

\subsection{First subsection}
\scenario{My first scenario}
\scenario{My second scenario}

\subsection{Second subsection}
\scenario{My third scenario}
Counter restarts.
\end{document}

I'm sure that I must be making some mistake, because even though it produces the desired result, now the TOC compiles incorrectly, showing the scenarios even though I defined TOC depth to 1.

What mistake am I making on the definition of the custom heading? I tried looking on this site or the titlesec documentation, but haven't been able to solve it.

han-tyumi
  • 1,152
  • 8
  • 17
  • 1
    Please complete your code so that it can be compiled into a small document reproducing the issue. That is much more useful than mere fragments. – cfr Aug 22 '14 at 21:38
  • I'll try, but it's a very complex document. That's why I didn't post a MWE. – han-tyumi Aug 22 '14 at 21:43
  • 2
    If you can't produce an MWE, how do you expect other people to do so without even seeing the code that causes the problem? Producing an MWE is just a mechanical procedure: tedious but not demanding any particular skill beyond an ability to comment and uncomment code. You just comment code until the problem disappears. Then uncomment the last bit and start commenting other bits until the problem disappears (repeat) or there is nothing left you haven't tested. See minimal working example (MWE) for details. – cfr Aug 22 '14 at 21:48
  • I know how to produce a MWE, but I thought that someone who knows well how to use titlesec could pinpoint the mistake just by looking at the definition of the custom heading, so that a MWE wouldn't be necessary. Sorry, I updated my question accordingly. – han-tyumi Aug 22 '14 at 21:52
  • Well, you might be lucky. I guess it depends how badly you want a solution. Providing an MWE makes the question potentially answerable by more people and so increases your chances of getting a useful answer. My personal solution would be not to use titlesec since every time I try, I find it turns out to create more problems than it solves. However, I know it works well for others. – cfr Aug 22 '14 at 22:35
  • The \titleclass command doesn't appear to do what it says on the tin. According to the documentation, it should mean \scenario is level 2 and \subsection is level 3. Yet that does not appear to be the case at all... – cfr Aug 22 '14 at 23:00

2 Answers2

2

There appears to have a mess when you add new levels. I think the simplest solution is to use \subsubsection and the scenario command as an aliasfor \subsubsection. Her is how it can go:

\documentclass{article}
\usepackage{titlesec}
\usepackage{hyperref} 
%%% seccion para estatica comparativa
\titleformat{\subsubsection}
{\scshape}{(\thesubsubsection)}{0.5em}{}
\titlespacing*{\subsubsection }{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}
\renewcommand*{\thesubsubsection}{\Alph{subsubsection}}
\def\subsubsectionautorefname{scenario}
\let\scenario\subsubsection
\begin{document}
\setcounter{tocdepth}{2}
\tableofcontents

\section{First section}

\subsection{First subsection}
\scenario{My first scenario}
\label{scen1}
\scenario{My second scenario}

\subsection{Second subsection}
\scenario{My third scenario}
Counter restarts. As we can see in \autoref{scen1},…
\end{document} 

enter image description here

Bernard
  • 271,350
  • (+1) for the mess. I tried to figure out the code for the macro but didn't manage to achieve anything. – cfr Aug 23 '14 at 00:29
  • Your solution works but redefines al subsubsections, which I'm also using, so it doesn't really solve the problem. – han-tyumi Aug 24 '14 at 13:37
0

I found that the best approach was simply to define a new command (scenario) that uses an unnumbered subsubsection with the formatting I want and attached to a new counter, like this:

\newcounter{scenariocount}[subsection]
\newcommand{\scenario}[1]
{
\stepcounter{scenariocount}
\subsubsection*{\textmd{\textsc{(\Alph{scenariocount}) #1 }}}  
}

No extra packages are needed and no conflicts with the TOC or other subsubsections arise.

han-tyumi
  • 1,152
  • 8
  • 17