# How can I format sections/subsections/etc. like nested lists?

I would like to format sections/subsections/etc. so that the entire body text of subsections is indented relative to the body text of the parent section as it is for nested lists, i.e.

1. Section heading.  Lorem ipsum dolor sit amet, consectetur adipisicing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

a. Subsection heading.  Duis aute irure dolor in reprehenderit in voluptate
velit esse cillum dolore eu fugiat nulla pariatur.


I am currently using the titlesec package to achieve the run-in section heading with the following macros:

\titleformat{\section}[runin]{\normalfont\bfseries}{\thesection.}{.5em}{}[\quad]

\titlespacing{\subsection}{\parindent}{*2}{\wordsep}


The resulting output looks like this:

1. Section heading.  Lorem ipsum dolor sit amet, consectetur adipisicing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

a. Subsection heading.  Duis aute irure dolor in reprehenderit in voluptate
velit esse cillum dolore eu fugiat nulla pariatur.


I've tried using the hanging package and the underlying \hangindent and \hangafter commands in the \titleformat definitions, but nothing I've tried has produced the desired results.

-
Just out of curiosity, is there some reason you don't want to use lists? –  TH. Aug 31 '10 at 4:35
The particular document in question is a compiled code of legislation, analogous to the United States Code ( gpoaccess.gov/uscode ), so it's much more semantic to mark it up with \section{heading}, \subsection{heading}, etc., than to use \item \textbf{heading} –  las3rjock Aug 31 '10 at 5:06

Not really. In theory, the \section command could be rewritten to adjust the page layout, but that would not be fun. Also, it could be ambiguous, sometimes, where sections end. I recommend instead something like the following, where you redefine the section headings into environments and then change the margins with the changepage package. .

\documentclass[twoside]{article}
\usepackage{changepage,lipsum}
\newenvironment{h1}[2][]{\section[#1]{#2}}{}
\newenvironment{h2}[2][]{%
\subsection[#1]{#2}%
}{%
}
\newenvironment{h3}[2][]{%
\subsubsection[#1]{#2}%
}{%
}
\begin{document}
\begin{h1}{first}
\lipsum[1]
\begin{h2}{second}
\lipsum[2]
\end{h2}
\begin{h2}{third}
\lipsum[3]
\begin{h3}{fourth}
\lipsum[4]
\end{h3}
\end{h2}
\end{h1}
\end{document}


Changing the formatting of the section headings can be done, as you mention, with titlesec.

-

Even if you could insert somehow code to indent the following text in the (sub)section commands you will run into problems at the next subsection as it will indent the text even more. You should better surround the one of the changemargin commands (http://www.tex.ac.uk/cgi-bin/texfaq2html?label=chngmargonfly) e.g. the one of the KOMA-classes:

\documentclass{scrartcl}
\usepackage{lipsum}
\usepackage{titlesec}
\titlespacing{\section}{-1cm}{*2}{\wordsep}
\titlespacing{\subsection}{-1cm}{*2}{\wordsep}
\begin{document}