2

Original question (i): My section headings are in the form 'Scenario 1: Learning to use LaTeX' etc so it looks stupid when the heading is printed as '1 Scenario 1: Learning to use LaTeX'. Therefore I'd like to hide the section numbering.

However I still want the equation numbers to be by section (so the first equation in section 1 is labelled (1.1) etc).

I've tried putting \numberwithin{equation}{section} in the preamble and using \section*{...} but then the equation numbers in all the sections are (0.1), (0.2) etc.

Any ideas on how to do this? Thanks in advance!

Follow-up Question (ii): This is a more specific question to my paper, about how to write up the sections so that the numberings make sense.

My paper has the following sections, and I've written next to each how I'd like the equations to be numbered:

Scenario 1 (1.1),(1.2) etc

Scenario 2 (2.1) etc

Scenario 3 (3.1) etc

Scenario 4 (4.1) etc

Scenario 5 (5.1) etc

Scenario H1 (H1.1) etc

Scenario 8 (8.1) etc

Scenario H2 (H2.1) etc

Supplementary Information

The Supplementary Information also has subsections:

Scenario 1 Numbers follow on from Scenario 1 above eg (1.9),(1.10) etc

Scenario 2 As above, eg (2.7) etc

Scenario 6 (6.1) etc

Scenario 7 (7.1) etc

5
  • 3
    Welcome to the site. Please edit your question and provide a small, but complete working example that demonstrates the issue, beginning with \documentclass. Jun 17, 2021 at 10:49
  • \numberwithin*{equation}{section} should do what you want.
    – Bernard
    Jun 17, 2021 at 13:45
  • I just tried putting this in and it comes up with an error ('no counter '*' defined').
    – Daphne
    Jun 17, 2021 at 16:28
  • Where is \numberwithin defined? The kernel provides \counterwithin which I use. Jun 17, 2021 at 16:57
  • @PeterWilson I'm not fully sure what you mean? I think \numberwithin comes from the amsmath package.
    – Daphne
    Jun 17, 2021 at 17:03

2 Answers 2

3

W.r.t the original question (i)

You could redefine the section and equation numbers in this way--

\documentclass{article}

\usepackage{amsmath}

\renewcommand{\thesection}{Scenario \arabic{section}:}
\renewcommand{\theequation}{\arabic{section}.\arabic{equation}}

\begin{document}

  \section{Solving equations in \LaTeX}
  
  Consider the equation with one variable---
  \begin{equation}
    a^2 + 2a = 8
  \end{equation}
  which solves as $a = 2$.
  
  \section{Moving deeper}
  
  Two equations with two unknowns---
  \begin{align}
    a &= b + 3 \\
    b &= 2
  \end{align}
  boils down to $a = 5$.

  \section{The harder part}
  
  Two equations with three unknowns do not have a unique solution\ldots
  \begin{align}
    a &= b + c \\
    b &= c - 5
  \end{align}
  solves for any value of $c$.

\end{document}

which produces this--

output

W.r.t the first part of the follow-up question (ii)

Addressing the need for an additional Scenario H1 (only the first part to this question), something like this--

revised output

...could be achieved by combining my answer with @Werner's more robust, low-level(?) TeX solution ...somewhat close to @egreg's answer, and defining two section-like commands

  • \scenario{...} and
  • \scenarioh{...}

with their respective counters scenario and scenarioh according to normal LaTeX protocol (please pardon my limited TeX knowledge).

\documentclass{article}

\usepackage{amsmath}
\numberwithin{equation}{section}

\makeatletter
\renewcommand{\@seccntformat}[1]{%
      Scenario~\csname the#1\endcsname:\quad}
\makeatother

\newcounter{scenario}
\newcounter{scenarioh}

\renewcommand{\theequation}{\arabic{section}.\arabic{equation}}


\newcommand{\scenario}[1]{
              \addtocounter{scenario}{1}
              \renewcommand{\thesection}{%
                      \arabic{scenario}%
                                        }
              \section{#1}
              \renewcommand{\theequation}{%
                      \arabic{scenario}.\arabic{equation}%
                                         }
                         }

\newcommand{\scenarioh}[1]{
              \addtocounter{scenarioh}{1}
              % A  "Scenario H" will normally
              % increment the "Scenario" counter by 1
              \addtocounter{scenario}{1} 
              \renewcommand{\thesection}{%
                      H\arabic{scenarioh}%
                                        }
              \section{#1}
              \renewcommand{\theequation}{%
                      H\arabic{scenarioh}.\arabic{equation}%
                                         }
                         }

\newcommand{\skipscenario}{\addtocounter{scenario}{1}}


\begin{document}

\scenario{Solving equations in \LaTeX}\label{sec:sol}

Consider the equation with one variable---
\begin{equation}
  a^2 + 2a = 8
\end{equation}
which solves as $a = 2$, or $a = -4$.

\scenario{Moving deeper}

Two equations with two unknowns---
\begin{align}
  a &= b + 3 \\
  b &= 2
\end{align}
boils down to $a = 5$, being the only root, unlike \S\,\ref{sec:sol}.

\scenario{The harder part}

Two equations with three unknowns do not have a unique solution\ldots
\begin{align}
  a &= b + c \\
  b &= c - 5
\end{align}
solves for any value of $c$.


\scenarioh{Weird use cases}\label{sec:weird}

Fermat's last theorem states---
\begin{align}
  a^n + b^n = c^n  \qquad n > 2
  \label{eq:weird}
\end{align}
We skip a the next scenario and move on to scenario \ref{sec:iden}.

\skipscenario

\scenario{Identities}\label{sec:iden}

Let's take the identity---
\begin{equation}
  a \equiv a
\end{equation}
which might have a remote reference to equation \eqref{eq:weird} in \$\,\ref{sec:weird}.


\end{document}

Note that--

  1. There's an option to skip a section with \skipscenario (implemented after Scenario 3).
  2. References to sections and equations now appear right, courtesy @egreg.

Yet-unsolved part: Supplementary Information

This will definitely need storing the equation counters from all preceding sections (scenarios and scenariohs) and re-implementing them when the older sections are referred back.

Still remains an open problem here.

9
  • That's really helpful, thank you!
    – Daphne
    Jun 17, 2021 at 16:28
  • Just to make things a little more complicated, I'd like to label one of my scenaria 'Scenario H1' instead of eg 'Scenario 6'. Is there a way I can do that too? Thanks.
    – Daphne
    Jun 17, 2021 at 16:31
  • So, what does H1 stand for ? In particular, (i) should the next scenario be numbered continuing to 6, or skipped to 7 (assuming the one before H1 was 'Scenario 5'), and (ii) would you like some 'Scenario H2' also, later... or just one exception would suffice ? Would be good if you could edit your answer accordingly !
    – Partha D.
    Jun 17, 2021 at 16:36
  • Apologies! I'll edit the question to explain what I need properly.
    – Daphne
    Jun 17, 2021 at 16:39
  • I've updated the question - thanks!
    – Daphne
    Jun 17, 2021 at 17:02
1

Rather than redefining \thesection you should redefine how to print the section number.

Here I change the default meaning of \@seccntformat to look whether \format<level> is defined and in this case use it; otherwise it sticks to the default.

\documentclass{article}
\usepackage{amsmath}

\counterwithin{equation}{section}

\makeatletter
\renewcommand{\@seccntformat}[1]{%
  \ifcsname format#1\endcsname
    \csname format#1\endcsname
  \else
    \csname the#1\endcsname\quad % default
  \fi
}
\makeatother

\newcommand{\formatsection}{Scenario \thesection: }

\begin{document}

\section{Solving equations in \LaTeX}
  
Consider the equation with one variable
\begin{equation}
a^2 + 2a = 8
\end{equation}
which solves as $a = 2$.
  
\section{Moving deeper}
  
Two equations with two unknowns
\begin{align}
  a &= b + 3 \\
  b &= 2
\end{align}
boils down to $a = 5$.

\section{The harder part}
  
Two equations with three unknowns do not have a unique solution
\begin{align}
  a &= b + c \\
  b &= c - 5
\end{align}
solves for any value of $c$.

\end{document}

I took the body from Partha D.'s answer for laziness.

Why not to redefine \thesection? Because with \ref you'd end up with unwanted bits of information.

enter image description here

1
  • Ah I hadn't thought of \ref. Could you explain a little more what you are doing in the preamble (from \makeatletter to \makeatother)?
    – Daphne
    Jun 17, 2021 at 17:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.