3

I'd like to restart the numbering of the sidenotes each subsection, to prevent sidenote 1000 at the end of the book. So I'm using this code:

\documentclass[10pt]{book}
\usepackage{geometry}

\usepackage[utf8]{inputenc}
\usepackage[latin]{babel}
\usepackage{sidenotes}
\usepackage{blindtext}
\usepackage[maxfloats=100]{morefloats}

\setlength{\marginparwidth}{2cm}

\makeatletter
\@addtoreset{sidenote}{subsection}
\makeatother

\begin{document}

\chapter{Hello}

\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}

\chapter{Hi}

\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}\blindtext\sidenote{hello}

\end{document}

The problem is however, that the sidenotes begin in each section (chapter) with sidenote 0, not sidenote 1. How can I solve this? Or is this a bug?

  • I get a 'too many unprocessed floats' error -- please make your file compilable – user31729 Oct 8 '17 at 7:46
  • Sorry I've used pdflatex -interaction=nonstopmode test.tex, I'll look into the reason of this problem – L.A. Rabida Oct 8 '17 at 7:59
  • The morefloats package seems to solve the 'too many unprocessed floats' error, I'll update my example – L.A. Rabida Oct 8 '17 at 8:01
  • @ChristianHupfer I don't see your answer anymore, but it was only a typo, a missing %. So your answer worked just as well. Thanks again! – L.A. Rabida Oct 8 '17 at 14:42
  • I have deleted my answer after you complained and unaccepted it before giving me the chance to correct errors... – user31729 Oct 8 '17 at 15:48
2

You'll run into problems if a \sidenote doesn't appear after a \subsection command.

Anyway, there is a simple workaround. I use openany just to show that the counter is properly reset at chapter breaks (actually, it is only at subsections).

\documentclass[10pt,openany]{book}
\usepackage{geometry}

\usepackage[utf8]{inputenc}
\usepackage[latin]{babel}
\usepackage{sidenotes}
\usepackage[maxfloats=100]{morefloats}
\usepackage{chngcntr}

\geometry{
  marginparwidth=2cm,
}

\counterwithin*{sidenote}{subsection}
\makeatletter
\renewcommand{\thesidenote}{\@arabic{\numexpr\value{sidenote}+1\relax}}
\makeatother

\begin{document}

\chapter{Hello}

\section{Title}

\subsection{Subtitle}
Some text\sidenote{hello} that should occupy at least three lines, let's see whether 
this is enough, but probably not, so we add some words. But probably we need some
more of this boring text in order that it goes on and eventually split across three lines.
Some text\sidenote{hello} that should occupy at least three lines, let's see whether 
this is enough, but probably not, so we add some words. But probably we need some
more of this boring text in order that it goes on and eventually split across three lines.

\subsection{Subtitle}
Some text\sidenote{hello} that should occupy at least three lines, let's see whether 
this is enough, but probably not, so we add some words. But probably we need some
more of this boring text in order that it goes on and eventually split across three lines.
Some text\sidenote{hello} that should occupy at least three lines, let's see whether 
this is enough, but probably not, so we add some words. But probably we need some
more of this boring text in order that it goes on and eventually split across three lines.


\chapter{Hi}

\section{Title}

\subsection{Subtitle}
Some text\sidenote{hello} that should occupy at least three lines, let's see whether 
this is enough, but probably not, so we add some words. But probably we need some
more of this boring text in order that it goes on and eventually split across three lines.
Some text\sidenote{hello} that should occupy at least three lines, let's see whether 
this is enough, but probably not, so we add some words. But probably we need some
more of this boring text in order that it goes on and eventually split across three lines.

\subsection{Subtitle}
Some text\sidenote{hello} that should occupy at least three lines, let's see whether 
this is enough, but probably not, so we add some words. But probably we need some
more of this boring text in order that it goes on and eventually split across three lines.
Some text\sidenote{hello} that should occupy at least three lines, let's see whether 
this is enough, but probably not, so we add some words. But probably we need some
more of this boring text in order that it goes on and eventually split across three lines.

\end{document}

enter image description here

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.