0

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.

2
  • To clarify: you don't want the numbers of the subsubsections but their names? Or can the names be calculated from the numbers? Commented Jul 4, 2017 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. Commented Jul 4, 2017 at 14:05

2 Answers 2

2

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
\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}}%
    \addtocounter{start}{1}%
    \setcounter{stop}{\ObtainTrackedValueExp[\value{section}]{section}{subsubsection}}%
    \addtocounter{stop}{\value{start}}%
    \addtocounter{stop}{-1}%
    \ifnum\ObtainTrackedValueExp[\value{section}]{section}{subsubsection}>0
        \S \arabic{start} -- \S \arabic{stop}
    \fi
    #1
}{0pt}{}

% fix from https://topanswers.xyz/tex?q=1987#a2230
\ExplSyntaxOn
\cs_set_eq:NN \c_zero \c_zero_int
\ExplSyntaxOff

\begin{document}

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

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

\section{Third section}

\end{document}

enter image description here

4
  • 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 Commented Jul 6, 2017 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. Commented Jul 6, 2017 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 Commented Jul 6, 2017 at 21:02
  • @dfherr You're welcome! For the headings you probably have to define reasonable content for chapters. Commented Jul 6, 2017 at 21:08
2

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}}
\addcontentsline{toc}{section}{\S\arabic{sectionstart}\enspace\textendash\enspace\S\arabic{sectionend}\quad Section 1}
\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}
\addcontentsline{toc}{section}{\S\arabic{sectionstart}\space ff.\enspace Section 1}

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

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

\end{document}

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.