[Tex/LaTex] How to format sections/subsections/etc. like nested lists

listssectioningsections-paragraphs

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]

\titleformat{\subsection}[runin]{\normalfont\bfseries}{\thesubsection.}{.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.

Best Answer

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][]{%
  \begin{adjustwidth}{2em}{}
    \subsection[#1]{#2}%
}{%
  \end{adjustwidth}
}
\newenvironment{h3}[2][]{%
  \begin{adjustwidth}{2em}{}
    \subsubsection[#1]{#2}%
}{%
  \end{adjustwidth}
}
\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.

Related Question