0

I am compiling a solution file with exercises from different sections of a book, so I hope the exercises are numbered as sectionnumber.subsectionnumber.exercisenumber. The issue arises since the book's subsection labeling is particular: it is a combination of numbers and alphabets, so after subsection 1.1, 1.2, for example, it would then start alphabetically like subsections 1.A and 1.B (I assume to illustrate unimportant materials). I am looking for a way to customize the counter so that the subsections and exercises are numbered correspondingly. Thanks!


Update: Just saw this post, which solves most of the issue. I am still hoping to find a more ''automatic'' way of doing this, like using counter, etc.


For a working example, say

\documentclass[12pt]{article}
\usepackage[letterpaper, margin=1in]{geometry}
\usepackage{amsmath, amssymb, mathtools, tikz-cd, enumitem, fancyhdr, mleftright, wrapfig, scrextend,mathrsfs,amsthm}

\theoremstyle{definition} \newtheorem{exercise}{Exercise}[subsection] \newtheorem{corollary}{Corollary}[exercise] \newtheorem{lemma}{Lemma}[exercise] \newtheorem{proposition}{Proposition}[exercise] \newtheorem{claim}{Claim}[exercise] \newtheorem{remark}{Remark}[exercise]

\begin{document}

\section{Section 1}

\begin{exercise} % 1.0.1

\end{exercise}

\subsection{Subsection 1.1}

\begin{exercise} % 1.1.1

\end{exercise}

\subsection{Subsection 1.2}

\begin{exercise} % 1.2.1

\end{exercise}

\subsection{Subsection 1.A}

\begin{exercise} % 1.A.1

\end{exercise}

\subsection{Subsection 1.B}

\begin{exercise} % 1.B.1

\end{exercise}

\section{Section 2}

\subsection{Subsection 2.1}

\begin{exercise} % 2.1.1

\end{exercise}

\subsection{Subsection 2.2}

\end{document}

1 Answers1

1

You could define a commend, that changes the subsection numbering style redefining \thesubsection and also stores the last value of the previous numbering style and optionally restores this value. In the example below \subsectionnumbering{<style>} would restore the previously last number of the style, but the star variant \subsectionnumber*{<style>} would always start with 1.

\documentclass[12pt]{article}
\usepackage[letterpaper, margin=1in]{geometry}
\usepackage{amsmath, amssymb, mathtools, tikz-cd, enumitem, fancyhdr, mleftright, wrapfig, scrextend,mathrsfs,amsthm}

\theoremstyle{definition} \newtheorem{exercise}{Exercise}[subsection] \newtheorem{corollary}{Corollary}[exercise] \newtheorem{lemma}{Lemma}[exercise] \newtheorem{proposition}{Proposition}[exercise] \newtheorem{claim}{Claim}[exercise] \newtheorem{remark}{Remark}[exercise] \errorcontextlines\maxdimen \makeatletter \newcommand{\currentsubsectionnumbering}{arabic} \NewDocumentCommand{\subsectionnumbering}{sm}{% \expandafter\edef\csname lastsubsection\currentsubsectionnumbering number\endcsname {\expandafter\the\value{subsection}}% \renewcommand{\thesubsection}{\thesection.@nameuse{#2}{subsection}}% \setcounter{subsection}{0}% \IfBooleanF{#1}{% star variant don't set it to the last used number of the numbering style @ifundefined{lastsubsection#2number}{}{% \setcounter{subsection}{@nameuse{lastsubsection#2number}}% }% } @namedef{currentsubsectionnumbering}{#2}% } \makeatother

\begin{document}

\section{Section 1}

\begin{exercise} % 1.0.1

\end{exercise}

\subsection{Subsection 1.1}

\begin{exercise} % 1.1.1

\end{exercise}

\subsection{Subsection 1.2}

\begin{exercise} % 1.2.1

\end{exercise}

\subsectionnumbering{Alph} \subsection{Subsection 1.A}

\begin{exercise} % 1.A.1

\end{exercise}

\subsection{Subsection 1.B}

\begin{exercise} % 1.B.1

\end{exercise}

\subsectionnumbering{arabic} \subsection{Subsection 1.3}

\begin{exercise} % 1.1.1

\end{exercise}

\subsectionnumbering{Alph} \subsection{Subsection 1.C}

\begin{exercise} % 1.C.1

\end{exercise} \subsectionnumbering{arabic}% should be BEFORE \section

\section{Section 2}

%\subsectionnumbering*{arabic}% alternative: use the star variant to start % again with subsection number 1 \subsection{Subsection 2.1}

\begin{exercise} % 2.1.1

\end{exercise}

\subsectionnumbering*{Alph}% Here we don't want to use the previous upper case % letter value, but want to start new. \subsection{Subsection 2.A}

\begin{exercise} % 2.A.1

\end{exercise}

\end{document}

enter image description here

cabohah
  • 11,455