1

I want to enumerate my solutions to some exercise from a book. The names of the exercises are structured in the form "CHAPTER.ExerciseNumber.ExerciseSubNumber", e.g.:

1.1)a) b) c)

1.2)

1.3)

2.1)

...

I have used the following codestyle for other books (where there were no subnumbers):

\documentclass[a4paper, 11pt]{article}
\usepackage[a4paper,left=3cm,right=3cm,top=3cm,bottom=3cm]{geometry}


\usepackage{array}
\usepackage{enumitem}
\usepackage{etoolbox}
\usepackage{fancyhdr}
\usepackage{float}
\usepackage[T1]{fontenc}
\usepackage[Export]{adjustbox}
\usepackage[utf8]{inputenc}
\usepackage{latexsym}
\usepackage{lmodern}
\usepackage{mdframed}
\usepackage{pifont}
\usepackage{pgf}
\usepackage{ragged2e}
\usepackage{tcolorbox}
\usepackage{tikz}
\usepackage[absolute,overlay]{textpos}
\usepackage{ulsy}
\usepackage{xcolor}


\pagestyle{fancy}
\fancyhf{}
\renewcommand{\headrulewidth}{0pt}
\fancyfoot[LE,RO]{\thepage}
\renewcommand{\familydefault}{\sfdefault}

\newcounter{mycount} \renewcommand{\themycount}{\arabic{mycount}}
\setlist[enumerate]{label=\themycount.\arabic*,
    ref=\themycount.\arabic*),
    before=\refstepcounter{mycount}}
\setcounter{mycount}{0}


\begin{document}
    
    
    \begin{enumerate}
        \item   \begin{enumerate}[label=\alph*)]
                    \item 
                    \item 
                    \item 
                \end{enumerate}
        \item 
        \item
    \end{enumerate}
    
    \begin{enumerate}
        \item 
    \end{enumerate}

\end{document}

However, this code does not work for sub-enumerations (the chapter number gets mistakingly incremented by one). Is there any way to fix this?

1
  • 1
    Off-topic: left=3cm,right=3cm,top=3cm,bottom=3cm may be expressed more succinctly as margin=3cm.
    – Mico
    Commented Mar 15 at 0:54

1 Answer 1

1

However, this code does not work for sub-enumerations -- the chapter number gets [mistakenly] incremented by one. Is there any way to fix this?

You need to change

\setlist[enumerate]{..., before=...}

to

\setlist[enumerate,1]{..., before=...}

to assure that the before option is not executed at that start of level-2 enumerate environments as well.

A separate issue: You also need to exchange the assignments of the label and ref options for level-1 enumerate items.

enter image description here

\documentclass[a4paper, 11pt]{article}
\usepackage[margin=3cm]{geometry}

%% I've commented out all instructions that 
%% aren't needed for the example at hand.

%\usepackage{array}
\usepackage{enumitem}
%\usepackage{etoolbox}
%\usepackage{fancyhdr}
%\usepackage{float}
%\usepackage[T1]{fontenc}
%\usepackage[Export]{adjustbox}
%\usepackage[utf8]{inputenc}
%\usepackage{latexsym}
%\usepackage{lmodern}
%\usepackage{mdframed}
%\usepackage{pifont}
%\usepackage{pgf}
%\usepackage{ragged2e}
%\usepackage{tcolorbox}
%\usepackage{tikz}
%\usepackage[absolute,overlay]{textpos}
%%%%\usepackage{ulsy}
%\usepackage{xcolor}

%\pagestyle{fancy}
%\fancyhf{}
%\renewcommand{\headrulewidth}{0pt}
%\fancyfoot[LE,RO]{\thepage}
\renewcommand{\familydefault}{\sfdefault}

\newcounter{mycount} 
%\setcounter{mycount}{0} % that's the default
%\renewcommand{\themycount}{\arabic{mycount}} % that's the default
\setlist[enumerate,1]{%
          label =\themycount.\arabic*) ,
          ref   =\themycount.\arabic*  ,
          before=\refstepcounter{mycount}}

\begin{document} 
    
    \begin{enumerate}
        \item   \begin{enumerate}[label=\alph*)]
                    \item 
                    \item 
                    \item 
                \end{enumerate}
        \item 
        \item
    \end{enumerate}
    
    \begin{enumerate}
        \item 
    \end{enumerate}

\end{document}
1
  • Thanks a lot for your help, you solved my issue! :)
    – 3nondatur
    Commented Mar 15 at 11:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .