# Indenting text after numbered paragraphs

I have a 60 page document with numbered Sections, subsections and paragraphs. All the paragraphs are numbered. I want all the text to be indented evenly after the numbered paras, such as the following example shows:

1.      Section

1.1     Subsection

1.1.1   Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Donec rhoncus non ante faucibus tempus. Quisque ex orci,
faucibus vitae magna sed, blandit fermentum massa.

1.1.2   Some numbered paras interrupted by lists:
* Item 1
* Item 2
* Item 3
and some text to finish the paragraph

1.1.2   Some numbered paras interrupted by sets of equations using AMSmath:

A = B
C = D

and some text to finish the paragraph


Currently, I have some 60 pages of text (including lots of equations), built around the following koma-script class:

% -*- 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{}}
%
%
% make sure paragraphs reset counting at section and subsections
%
\makeatletter
\makeatother
%
% AND NOW WE BEGIN
%
\begin{document}
\section{Section}
\subsection {Subsection}
\p \blindtext
% 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$.
\end{document}


so, all the text returns to the left hand margin. It would be ideal if I could use something like the koma-script \addmargin command to indent lists and maths from the left; but adjust the \p numbered paragraph command so that its numbering started flush on the left, but with a box round the number to give it a standard size, and then a hanging command for the remainder of the \p para to even it up with the rest of the indented text.

Or, something else ....

But so far, this is beyond my LaTeX skill set.

• Does tex.stackexchange.com/q/109328/15925 do something like what you are looking for? – Andrew Swann Dec 22 '14 at 11:07
• this one looks a bit closer: How can I number paragraphs (and sections) in the margin? – barbara beeton Dec 22 '14 at 13:38
• Placing \let\svthesection\thesection\def\thesection{\kern-1.5cm\svthesection}\hoffset=\dimexpr\the\hoffset + 1.5cm\relax\textwidth=\dimexpr\textwidth-1.5cm\relax in the preamble takes care of the immediate problem, but introduces others like messing up the centering of headers/footers (i.e., page numbers). – Steven B. Segletes Dec 22 '14 at 17:30
• Steven. That works brilliantly. All it needed as \begin{addmargin} to finish it off. – DACN Dec 22 '14 at 18:56
• You need to use an at symbol to ping @StevenB.Segletes if you'd like to ask for an answer you can accept? – cfr Dec 23 '14 at 4:05

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:
%
% make sure paragraphs reset counting also at sections
%
\makeatletter
\makeatother
% to reset headwidth and footwidth
\usepackage[
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:
%
% make sure paragraphs reset counting also at sections
%
\makeatletter
\makeatother


To reset the original headwidth and footwidth you can use

\usepackage[
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:
%
% make sure paragraphs reset counting also at sections
%
\makeatletter
\makeatother
% to reset headwidth and footwidth
\usepackage[
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:


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:
% to reset headwidth and footwidth
\usepackage[
footsepline% to show the footwidth
]{scrlayer-scrpage}
%
% make sure paragraphs reset counting at section and subsections
%
\makeatletter
\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}

• The answer above builds on the excellent work from @Steven. I hadn't realised that there would be problems in adding in section references (of which I have many section/subsection/paragraph references in my original). Resetting the headwidth and page width is a bonus which makes the pages look much better – DACN Dec 26 '14 at 21:46

As I [approximately] suggested in the comment, add these lines to the preamble

\let\svthesection\thesection
\def\thesection{\kern-1.5cm\svthesection}
\hoffset=\dimexpr\hoffset + 1.5cm\relax
\textwidth=\dimexpr\textwidth-1.5cm\relax
\paperwidth=\dimexpr\paperwidth -1.5cm\relax


What they accomplish is: 1) saving a copy of \thesection; 2) redefining \thesection to kern 1.5 cm to the left before printing out the section header; 3) modifying \hoffset to shift the whole document 1.5 cm to the right; 4) reducing the \textwidth by 1.5cm (combined with the \hoffset, leaves the right margin unchanged); and 5) reduces the paperwidth by 1.5cm, to account for the \hoffset modification.

I indicated that there were associated drawbacks to this approach, which are observable in the figures below the MWE. The header/footer are shifted, which means that centered page numbers are now shifted 0.75 cm to the right, compared to the OP's original code.

The OP indicated that this approach worked for his/her need, and requiring only the addition of a \begin{addmargin} environment. Since I am not exactly sure where the OP may have placed that additional code, I have not tried to insert it in my MWE.

Note that stray superscript marks ^ were removed from the OP's code in the align* environment (one removed per line), in order to facilitate compilation. This code was compiled in XeLaTeX, though it compiles in pdflatex as well.

% -*- 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{}}
%
%
% make sure paragraphs reset counting at section and subsections
%
\makeatletter
\makeatother

\let\svthesection\thesection
\def\thesection{\kern-1.5cm\svthesection}
\hoffset=\dimexpr\hoffset + 1.5cm\relax
\textwidth=\dimexpr\textwidth-1.5cm\relax
\paperwidth=\dimexpr\paperwidth -1.5cm\relax
%
% AND NOW WE BEGIN
%
\begin{document}
\section{Section}
\subsection {Subsection}
\p \blindtext
% 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$.
\end{document}


OP's ORIGINAL RESULT

WITH MY SUGGESTED CHANGE

• Thanks for the explanation. I suspect my final pre-amble will be a mix of your code above, and that from @esdd. The reason that I have recently moved from pdflatex to xelatex is for the ease of embedding true type fonts. My maths document is only one of a large suite of documents, the others being written in Word, and this allows for a more common look. – DACN Dec 26 '14 at 21:53
• @DACN glad to have been of assistance to you. – Steven B. Segletes Dec 26 '14 at 22:23