Simple Way to Format Section Titles
I am a bit unsure of how exactly you want these indentations to be, So I've created one where the section title would be at the same indentation-point across. The code is based on the example of a section given in the documentation section 9.1 A full example:
\titleformat{\section}
{\normalfont\Large\bfseries}{\thesection}{1em}{}
To get the same indentation-point, we need to calculate the width of the section-number, as these vary in width, depending on which number is being printed. (8 is wider than 1 in most fonts, and a 100 is ofcourse wider). This can be done with the command \widthof{content}
from the calc
-package. Then we set the length for the intendation to two \parindent
s, which is the length of a normal indent, minus the width of the section number.
But as the \parindent
is not the same everywhere, and is zero within the \titleformat
-macro, we need to calculate it outside of that. Therefore a new length is created, \anIndent
, which captures that length.
To get the indentation you want, I grabbed the answer by Werner posted in Indent an entire paragraph / section?. This works across pages, and is easier to use that a minipage
. It would ofcourse be great if there was some solution which worked without setting these macroes manually for every section.
Also, do you really want indentation of the first line? I don't think that is a very common way to do it. Normally, the first paragraph is not indented, only subsequent ones.
EDIT: I've now made a new environment, to make the syntax a bit better. It is based upon the adjustwidth
-environment from the changepage
-package. The new environment is called indentedSection
and takes one argument, the number of indentations. 1 for section
2 for subsection
and 3 for subsubsection
. I also added support for subsubsection
Output
Code
\documentclass[11pt]{article}
\usepackage{titlesec}
\usepackage{lipsum}
\usepackage{indentfirst}
\usepackage{calc}
\usepackage{changepage}
\newlength{\anIndent}
\setlength{\anIndent}{\parindent}
\titleformat{\section}
{\normalfont\Large\bfseries}{\thesection}{2\anIndent-\widthof{\thesection}}{}
\titleformat{\subsection}
{\normalfont\large\bfseries}{\thesubsection}{3\anIndent-\widthof{\thesubsection}}{}
\titleformat{\subsubsection}
{\normalfont\normalsize\bfseries}{\thesubsubsection}{4\anIndent-\widthof{\thesubsubsection}}{}
\newenvironment{indentedSection}[1]{%
%Input #1: Level of indentation
\begin{adjustwidth}{#1\anIndent+\anIndent}{}
\hspace{\anIndent}% Indent first line
\ignorespaces% Ignor any space at start of environment
}{\end{adjustwidth}}
\begin{document}
\section{Baz}
\begin{indentedSection}{1}
\lipsum[2]
\end{indentedSection}
\subsection{Foo}
\begin{indentedSection}{2}
\lipsum[2]
\end{indentedSection}
\subsubsection{hello}
\begin{indentedSection}{3}
\lipsum[2]
\end{indentedSection}
\end{document}