# Using subsection range for section numbering

Okay this might be an unconventional question.

I want to use the range of the subsections (or subsubsections for formatting reasons) as my section number.

So for:

\section{First section}
\subsubsection{\S1}
\subsubsection{\S2}
\subsubsection{\S3}


I would like to get the section heading and ToC entry:

§1 - §3 First section

So basically use the text of the first (sub)subsection and text of last last (sub)subsection of a section as the displayed section-"number".

I would not mind explicitly declaring this number at the beginning of each section, if it can't be done automatically.

• To clarify: you don't want the numbers of the subsubsections but their names? Or can the names be calculated from the numbers? – user36296 Jul 4 '17 at 13:56
• @samcarter The clauses are ongoing. So section 1 has clauses 5 to 9, section 2 has clauses 10 to 15, and so on. So the names could be calculated, but I have nothing in place yet. It's an articles of association document I'm rewriting in latex and the section numbers are really unimportant, as really only the clause numbers are important. – dfherr Jul 4 '17 at 14:05

You problem consists of a few distinguishable sub-problems:

1. Get numbered subsubsections in book class: \setcounter{secnumdepth}{3}

2. Continuous numbering of subsubsections: This can be done using remreset package to prevent the reset of the subsubsection counter.

3. To count the subsubsections per chapter, the package xcntperchap can be used

4. To format the section and subsubsection titles, I used the titlesec package

\documentclass{book}

% numbered subsubsections in book class
\setcounter{secnumdepth}{3}

% number subsubsections continiously
\usepackage{remreset}
\makeatletter
\@removefromreset{subsubsection}{chapter}
\@removefromreset{subsubsection}{section}
\@removefromreset{subsubsection}{subsection}
\makeatother

% count subsubsections per chapter
\usepackage{xcntperchap}
\RegisterTrackCounter{section}{subsubsection}

% format subsubsection titles
\usepackage[explicit]{titlesec}
\titleformat{\subsubsection}{\bfseries}{%
\S \arabic{subsubsection}
}{0pt}{}

% Format section
\newcounter{start}
\newcounter{stop}

\titleformat{\section}{\bfseries}{%
\setcounter{start}{\value{subsubsection}}%
\setcounter{stop}{\ObtainTrackedValueExp[\value{section}]{section}{subsubsection}}%
\ifnum\ObtainTrackedValueExp[\value{section}]{section}{subsubsection}>0
\S \arabic{start} -- \S \arabic{stop}
\fi
#1
}{0pt}{}

\begin{document}

\section{First section}
\subsubsection{}
\subsubsection{}
\subsubsection{}

\section{Second section}
\subsubsection{}
\subsubsection{}

\section{Third section}

\end{document}


• this look great! but it seems only to work with the article class (I'm using book for parts and appendix) and even with article I get the incorrect ToC entries – dfherr Jul 6 '17 at 20:39
• @dfherr This also works for book class. As for the toc, this can be changed using the same principle as the section titles for example with the etoc package. But as this questions already consist of so many meta questions, I suggest a dedicated one for the toc. – user36296 Jul 6 '17 at 20:54
• Very close to what I want. I'll try to figure out ToC with etoc package and get rid of the incorrect headings. But deserves to be accepted answer :) thank you – dfherr Jul 6 '17 at 21:02
• @dfherr You're welcome! For the headings you probably have to define reasonable content for chapters. – user36296 Jul 6 '17 at 21:08

I solved this introducing custom counters

\newcounter{clause}
\newcounter{sectionstart}
\newcounter{sectionend}

\begin{document}
\setcounter{sectionstart}{\value{clause}}
\section*{Section 1}
\refstepcounter{sectionstart}
\refstepcounter{clause}
\subsubsection{\textbf{\S\arabic{clause}}}

\refstepcounter{clause}
\subsubsection{\textbf{\S\arabic{clause}}}

\setcounter{sectionend}{\value{clause}}
\end{document}


Although this solution introduces wrong page numbers at the ToC due to the addcontentsline after the last subsubsection. I didn't know how to fix that wrong anchor, so I decided to just use the first Clause and append the german "ff." for "and the following" to the ToC.

The sectionstart counter is just for readability and could be skipped if the ToC code of the section is moved to the first clause.

\newcounter{clause}
\newcounter{sectionstart}

\begin{document}
\setcounter{sectionstart}{\value{clause}}
\refstepcounter{sectionstart} % increase by 1 as section should have at least 1 clause
\section*{Section 1}