Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
    
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
add comment

2 Answers 2

up vote 5 down vote accepted

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.

share|improve this answer
add comment

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}
\titleformat{\section}[runin]{\normalfont\bfseries}{\makebox[1cm][l]{\thesection.}}{0pt}{}[\quad]
\titleformat{\subsection}[runin]{\normalfont\bfseries}{\makebox[1cm][l]{\thesection.}}{0pt}{}[\quad]
\titlespacing{\section}{-1cm}{*2}{\wordsep}
\titlespacing{\subsection}{-1cm}{*2}{\wordsep}
\begin{document}
 \section{section heading} \lipsum[1]

\begin{addmargin}[1cm]{0cm}
 \leavevmode
 \subsection{sub heading} \lipsum[2]
 \begin{quote}
 \lipsum[1]
 \end{quote}
\end{addmargin}
\end{document}

If the text after your heading is simple (that means doesn't contain environments/commands like lists which change the margin) you can also simply advance \leftskip.

share|improve this answer
    
We had the same idea at the same time :) –  Will Robertson Aug 31 '10 at 9:43
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.