After giving a look at the linked document, I could detect six sectional units: chapters, sections, numbered subsections with title, numbered subsections without title, numbered subsubsections with title, and numbered subsubsections without title. So the problem is how to define these six sectional units.
The code below shows a possible solution using the titlesec package; the underlaying idea is to use \llap
and \parbox
es to typeset the numbers hanging onto the margin. The length \titleindent
allows you to easily control the hanging indent.
\paragraph
has been changed so that it will allow numbered subsections without title and \subparagraph
was also redefined to allow numbered subsubsections.
The following table shows the "dictionary" between each secional unit of the document and the LaTeX command that will be used to typeset it:
Chapters -> \chapter
Sections -> \section
Numbered subsections with title -> \subsection
Numbered subsections without title -> \paragraph
Numbered subsubsections with title -> \subsubsection
Numbered subsubsections without title -> \subparagraph
And here's the code (feel free to make the necessary adjustments to satisfy your requirements):
\documentclass{book}
\usepackage{titlesec}
\usepackage{etoolbox}
\usepackage{lipsum}
\setcounter{secnumdepth}{5}
\renewcommand\thesection{\arabic{section}}
% this length controls tha hanging indent for titles
% change the value according to your needs
\newlength\titleindent
\setlength\titleindent{2cm}
\pretocmd{\paragraph}{\stepcounter{subsection}}{}{}
\pretocmd{\subparagraph}{\stepcounter{subsubsection}}{}{}
\titleformat{\chapter}[block]
{\normalfont\huge\bfseries}{}{0pt}{\hspace*{-\titleindent}}
\titleformat{\section}
{\normalfont\Large\bfseries}{\llap{\parbox{\titleindent}{\thesection\hfill}}}{0em}{}
\titleformat{\subsection}
{\normalfont\large}{\llap{\parbox{\titleindent}{\thesubsection\hfill}}}{0em}{\bfseries}
\titleformat{\subsubsection}
{\normalfont\normalsize}{\llap{\parbox{\titleindent}{\thesubsubsection}}}{0em}{\bfseries}
\titleformat{\paragraph}[runin]
{\normalfont\large}{\llap{\parbox{\titleindent}{\thesubsection\hfill}}}{0em}{}
\titleformat{\subparagraph}[runin]
{\normalfont\normalsize}{\llap{\parbox{\titleindent}{\thesubsubsection\hfill}}}{0em}{}
\titlespacing*{\chapter}{0pt}{0pt}{20pt}
\titlespacing*{\subsubsection}{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}
\titlespacing*{\paragraph}{0pt}{3.25ex plus 1ex minus .2ex}{0em}
\titlespacing*{\subparagraph}{0pt}{3.25ex plus 1ex minus .2ex}{0em}
\begin{document}
\chapter{Test chapter}
\section{Test Section}
\lipsum[2]
\subsection{Test Subsection}
\lipsum[2]
\paragraph{}% acts like a numbered subsection without title
\lipsum[2]
\subsubsection{Test Subsubsection}
\lipsum[2]
\subparagraph{}% acts like a numbered subsubsection without title
\lipsum[2]
\end{document}
The previous approach assumes that you won't use \paragraph
and \subparagraph
with their standard formatting; another (perhaps more sensible) option is to define two fresh new sectional units; this, of course, requires a little additional work, but now you will have the standard sectional units plus the two new ones.
The following code illustrates this approach defining \subsectionwt
(for numbered subsections without titles) and \subsubsectionwt
(for numbered subsubsections without titles); it also makes the necessary provisions for the ToC.
The new "dictionary" is now:
Chapters -> \chapter
Sections -> \section
Numbered subsections with title -> \subsection
Numbered subsections without title -> \subsectionwt
Numbered subsubsections with title -> \subsubsection
Numbered subsubsections without title -> \subsubsectionwt
Paragraphs -> \paragraph
Subparagraphs -> \subparagraph
The example code:
\documentclass{book}
\usepackage{titlesec,titletoc}
\usepackage{etoolbox}
\usepackage{lipsum}
\setcounter{secnumdepth}{5}
\renewcommand\thesection{\arabic{section}}
% this length controls tha hanging indent for titles
% change the value according to your needs
\newlength\titleindent
\setlength\titleindent{2cm}
% counters for the new sectional units
\newcounter{subsectionwt}
\newcounter{subsubsectionwt}
% definition of the new sectional units with the representation of the counters
\titleclass{\subsectionwt}{straight}[\subsubsection]
\renewcommand{\thesubsectionwt}{\thesection.\arabic{subsectionwt}}
\titleclass{\subsubsectionwt}{straight}[\subsectionwt]
\renewcommand{\thesubsubsectionwt}{\thesubsection.\arabic{subsubsectionwt}}
% \subsection must increase the subsectionwt counter
% and \subsectionwt must increase the subsection counter
% Analogous treatment for \subsubsection and \subsubsectionwt
\pretocmd{\subsectionwt}{\stepcounter{subsection}}{}{}
\pretocmd{\subsection}{\stepcounter{subsectionwt}}{}{}
\pretocmd{\subsubsectionwt}{\stepcounter{subsubsection}}{}{}
\pretocmd{\subsubsection}{\stepcounter{subsubsectionwt}}{}{}
% format for the sectional units
\titleformat{\chapter}[block]
{\normalfont\huge\bfseries}{}{0pt}{\hspace*{-\titleindent}}
\titleformat{\section}
{\normalfont\Large\bfseries}{\llap{\parbox{\titleindent}{\thesection\hfill}}}{0em}{}
\titleformat{\subsection}
{\normalfont\large}{\llap{\parbox{\titleindent}{\thesubsection\hfill}}}{0em}{\bfseries}
\titleformat{\subsectionwt}[runin]
{\normalfont\large}{\llap{\parbox{\titleindent}{\thesubsectionwt\hfill}}}{0em}{\bfseries}
\titleformat{\subsubsection}
{\normalfont\normalsize}{\llap{\parbox{\titleindent}{\thesubsubsection}}}{0em}{\bfseries}
\titleformat{\subsubsectionwt}[runin]
{\normalfont\normalsize}{\llap{\parbox{\titleindent}{\thesubsubsectionwt}}}{0em}{\bfseries}
\titlespacing*{\chapter}{0pt}{0pt}{20pt}
\titlespacing*{\subsection}{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}
\titlespacing*{\subsectionwt}{0pt}{3.25ex plus 1ex minus .2ex}{0em}
\titlespacing*{\subsubsection}{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}
\titlespacing*{\subsubsectionwt}{0pt}{3.25ex plus 1ex minus .2ex}{0em}
% numbered entries without title shouldn't go to the ToC
\titlecontents{subsectionwt}[]{}{}{}{}
\titlecontents{subsubsectionwt}[]{}{}{}{}
\begin{document}
\tableofcontents
\chapter{Test chapter}
\section{Test Section}
\lipsum[2]
\subsection{Test Subsection}
\lipsum[2]
\subsectionwt{}% for numbered subsections without title
\lipsum[2]
\subsubsection{Test Subsubsection}
\lipsum[2]
\subsubsectionwt{}% for numbered subsubsections without title
\lipsum[2]
\end{document}
Update: KOMA-script version 3.17 (or newer)
With KOMA-Script version the command \othersectionlevelsformat
is depreciated. You have to use instead \sectionformat
, \subsectionformat
etc. So the code changes to
% -*- program: xelatex -*-
\documentclass[english, parskip=full, fontsize=11, DIV12, toc=left, numbers=noenddot]{scrartcl}
\usepackage{babel}
\usepackage{amsmath}
% just so we can see what is going on for now
\usepackage{showframe}
\usepackage{blindtext}
% tighten up spacing of lists
\usepackage{enumitem}
\setlist{noitemsep}
\setcounter{secnumdepth}{4}
\newcommand\p{\paragraph{}}
\newcommand\secnumindent{1.5cm}
\RedeclareSectionCommands[indent=-\secnumindent]{section,subsection,paragraph}
\RedeclareSectionCommand[afterskip=0pt,counterwithin=subsection]{paragraph}
\renewcommand\sectionformat{\parbox{\secnumindent}{\thesection\autodot}}
\renewcommand\subsectionformat{\parbox{\secnumindent}{\thesubsection\autodot}}
\renewcommand\subsubsectionformat{\parbox{\secnumindent}{\thesubsubsection\autodot}}
\renewcommand\paragraphformat{\parbox{\secnumindent}{\theparagraph\autodot}}
% from the answer of @Steven:
\addtolength\hoffset{\secnumindent}
\addtolength\textwidth{-\secnumindent}
%
% make sure paragraphs reset counting also at sections
%
\makeatletter
\@addtoreset{paragraph}{section}
\makeatother
% to reset headwidth and footwidth
\usepackage[
headwidth=\the\textwidth+\secnumindent:-\secnumindent,
footwidth=head:-\secnumindent,
headsepline,% to show the headwidth
footsepline% to show the footwidth
]{scrlayer-scrpage}
%
% AND NOW WE BEGIN
%
\begin{document}
\section{Section}
\subsection {Subsection}\label{sec:first}
\p \blindtext
% a reference
\p See \ref{sec:first}
% an example numbered paragraph with an embedded list
\p \blindtext
\begin{itemize}
\item Item 1
\item Item 2
\item Item 3
\end{itemize}
and some words at the end of this para
% an example numbered paragraph with a simple equation
\p The period is defined by a pair of days ($D_l$, $D_u$) where
\begin{align*}
D_{l} & = \text{the lower date} \\
D_{u} & = \text{the upper date}
\end{align*}
and things happen for all days $d$ where $D_l <= d< D_u$.
\section{Next section}
\subsection{Next subsection}
\p \blindtext
\end{document}
The result is the same as in the picture below.
If this should be compilable with versions 3.15 and 3.16 too insert
\renewcommand\othersectionlevelsformat[3]{\parbox{\secnumindent}{#3\autodot}}
\providecommand\sectionformat{}\providecommand\subsectionformat{}
\providecommand\subsubsectionformat{}\providecommand\paragraphformat{}
just before redefining \sectionformat
etc.
KOMA-script version 3.15 and 3.16
You can use the new commands \RedeclareSectionCommand
or \RedeclareSectionCommands
and redefine \othersectionlevelsformat
. So it is still possible to refer to a section number by \ref
:
\setcounter{secnumdepth}{4}
\newcommand\p{\paragraph{}}
\newcommand\secnumindent{1.5cm}
\RedeclareSectionCommands[indent=-\secnumindent]{section,subsection,paragraph}
\RedeclareSectionCommand[afterskip=0pt,counterwithin=subsection]{paragraph}
\renewcommand\othersectionlevelsformat[3]{\parbox{\secnumindent}{#3\autodot}}
% from the answer of @Steven:
\addtolength\hoffset{\secnumindent}
\addtolength\textwidth{-\secnumindent}
%
% make sure paragraphs reset counting also at sections
%
\makeatletter
\@addtoreset{paragraph}{section}
\makeatother
To reset the original headwidth and footwidth you can use
\usepackage[
headwidth=\the\textwidth+\secnumindent:-\secnumindent,
footwidth=head:-\secnumindent,
headsepline,% to show the headwidth
footsepline% to show the footwidth
]{scrlayer-scrpage}
Code:
% -*- program: xelatex -*-
\documentclass[english, parskip=full, fontsize=11, DIV12, toc=left, numbers=noenddot]{scrartcl}
\usepackage{babel}
\usepackage{amsmath}
% just so we can see what is going on for now
\usepackage{showframe}
\usepackage{blindtext}
% tighten up spacing of lists
\usepackage{enumitem}
\setlist{noitemsep}
\setcounter{secnumdepth}{4}
\newcommand\p{\paragraph{}}
\newcommand\secnumindent{1.5cm}
\RedeclareSectionCommands[indent=-\secnumindent]{section,subsection,paragraph}
\RedeclareSectionCommand[afterskip=0pt,counterwithin=subsection]{paragraph}
\renewcommand\othersectionlevelsformat[3]{\parbox{\secnumindent}{#3\autodot}}
% from the answer of @Steven:
\addtolength\hoffset{\secnumindent}
\addtolength\textwidth{-\secnumindent}
%
% make sure paragraphs reset counting also at sections
%
\makeatletter
\@addtoreset{paragraph}{section}
\makeatother
% to reset headwidth and footwidth
\usepackage[
headwidth=\the\textwidth+\secnumindent:-\secnumindent,
footwidth=head:-\secnumindent,
headsepline,% to show the headwidth
footsepline% to show the footwidth
]{scrlayer-scrpage}
%
% AND NOW WE BEGIN
%
\begin{document}
\section{Section}
\subsection {Subsection}\label{sec:first}
\p \blindtext
% a reference
\p See \ref{sec:first}
% an example numbered paragraph with an embedded list
\p \blindtext
\begin{itemize}
\item Item 1
\item Item 2
\item Item 3
\end{itemize}
and some words at the end of this para
% an example numbered paragraph with a simple equation
\p The period is defined by a pair of days ($D_l$, $D_u$) where
\begin{align*}
D_{l} & = \text{the lower date} \\
D_{u} & = \text{the upper date}
\end{align*}
and things happen for all days $d$ where $D_l <= d< D_u$.
\section{Next section}
\subsection{Next subsection}
\p \blindtext
\end{document}
KOMA-Script version 3.14 (or older)
Here is another suggestion using the answer by @Steven but redefining \othersectionlevelsformat
instead of \thesection
. So it is still possible to refer to a section number by \ref
:
\newcommand\p{\paragraph{}\hspace*{-1em}}
\newcommand\secnumindent{1.5cm}
\renewcommand\othersectionlevelsformat[3]{\makebox[0pt][r]{\parbox{\secnumindent}{#3\autodot}}}
% from the answer of @Steven:
\addtolength\hoffset{\secnumindent}
\addtolength\textwidth{-\secnumindent}
Code:
% -*- program: xelatex -*-
\documentclass[english, parskip=full, fontsize=11, DIV12, toc=left, numbers=noenddot]{scrartcl}
\usepackage{babel}
\usepackage{amsmath}
% just so we can see what is going on for now
\usepackage{showframe}
\usepackage{blindtext}
% tighten up spacing of lists
\usepackage{enumitem}
\setlist{noitemsep}
\setcounter{secnumdepth}{4}
\renewcommand\theparagraph{\thesubsection.\arabic{paragraph}}
\newcommand\p{\paragraph{}\hspace*{-1em}}
\newcommand\secnumindent{1.5cm}
\renewcommand\othersectionlevelsformat[3]{\makebox[0pt][r]{\parbox{\secnumindent}{#3\autodot}}}
% from the answer of @Steven:
\addtolength\hoffset{\secnumindent}
\addtolength\textwidth{-\secnumindent}
% to reset headwidth and footwidth
\usepackage[
headwidth=\the\textwidth+\secnumindent:-\secnumindent,
footwidth=head:-\secnumindent,
headsepline,% to show the headwidth
footsepline% to show the footwidth
]{scrlayer-scrpage}
%
% make sure paragraphs reset counting at section and subsections
%
\makeatletter
\@addtoreset{paragraph}{subsection}
\@addtoreset{paragraph}{section}
\makeatother
%
% AND NOW WE BEGIN
%
\begin{document}
\section{Section}
\subsection {Subsection}\label{sec:first}
\p \blindtext
% a reference
\p See \ref{sec:first}
% an example numbered paragraph with an embedded list
\p \blindtext
\begin{itemize}
\item Item 1
\item Item 2
\item Item 3
\end{itemize}
and some words at the end of this para
% an example numbered paragraph with a simple equation
\p The period is defined by a pair of days ($D_l$, $D_u$) where
\begin{align*}
D_{l} & = \text{the lower date} \\
D_{u} & = \text{the upper date}
\end{align*}
and things happen for all days $d$ where $D_l <= d< D_u$.
\section{Next section}
\subsection{Next subsection}
\p \blindtext
\end{document}
Best Answer
One could use the following definition of
\N
to achieve what you want:The paragraph number is placed in the margin using a "
\llap
" which is placed inside a box of width\parnumwidth
(set to3em
).You could also consider using a
\marginpar
, which allows you to place content in the margin in a more flexible way:You may adjust the placement, if needed.