12

So far, I've been trying code from various examples, and landed with:

\usepackage(titlesec)
\titleformat{\section}[block]{\bfseries}{\thesection.}{1em}{} 
\titleformat{\subsection}[block]{\hspace{2em}{\thesubsection}{1em}{}
\titleformat{\subsubsection}[block]{\hspace{3em}}{\thesubsubsection}{1em}{}

to indent the headers and their numbering. But I don't know how to get the content within each section/subsection/subsubsection to have an indented margin. In other words, I'd like to have the section/subsection/subsubsection content to be in line with it's indented header.

Is titlesec able to do this? I've been battling with the documentation, but I think they assume some more tex knowledge than I have as everything I try doesn't seem to work.

I'd like to use titlesec because, according to my understanding, I won't have to make any further adjustments while writing the document. I'm using pandoc to generate that part from markdown, so I can't have inline formatting on my sections.

Added the following as per comment requests:

Here is what I have:

What I have

And, here is what I would like:

What I would like

Or, I would like something like this:

I would like this also

4
  • 3
    Two thoughts: (1) not everyone knows what 'legal style indentation' looks like, and even 'to be in line with it's indented header' is not helpful (to me) --- is there no image you could point us to? (2) it is always better to provide a complete but minimal example that starts with \documentclass{<whatever>} and ends with \end{document}.
    – jon
    Apr 18, 2013 at 2:26
  • 1
    rather than indenting the body, change the margins of the document globally using geometry and alter the indent of the headings- this will be much easier
    – cmhughes
    Apr 18, 2013 at 3:08
  • Do you want to automate this? Of course, it is possible without automation...
    – Werner
    Apr 18, 2013 at 3:14
  • Thanks for the comments and suggestions, I would be ecstatic if I can automate this, but I may end up settling with @cmhughes idea of global margins. Otherwise, I'm open to more suggestions. I'm using documentclass{article} for no particular reason. Apr 18, 2013 at 3:34

2 Answers 2

8

This is surely possible, without automation, using the changepage package's adjustwidth environment:

enter image description here

\documentclass{article}
\usepackage{changepage,lipsum,titlesec}% http://ctan.org/pkg/{changepage,lipsum,titlesec}
\titleformat{\section}[block]{\bfseries}{\thesection.}{1em}{}
\titleformat{\subsection}[block]{}{\thesubsection}{1em}{}
\titleformat{\subsubsection}[block]{}{\thesubsubsection}{1em}{}
\titlespacing*{\subsection} {2em}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}
\titlespacing*{\subsubsection} {3em}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}
\begin{document}
\section{A section}
\lipsum[1]
\subsection{A subsection}
\begin{adjustwidth}{2em}{0pt}
  \lipsum[2]
\end{adjustwidth}
\subsubsection{A subsubsection}
\begin{adjustwidth}{3em}{0pt}
  \lipsum[3]
\end{adjustwidth}
\end{document}

The first argument to adjustwidth is the left-hand indentation, while the second is the right-hand indentation.

The above MWE also includes Gonzalo's suggestions for better alignment and true-to-titlesec spacing of sectional units using \titlespacing.

0
4

As a comparison, ConTeXt provides a \startsection...\stopsection version of the section heading commands, and keys beforesection and aftersection to hook into the start and stop of the section. So, one can simply set beforesection=\startnarrower and aftersection=\stopnarrower to get the desired effect.

In the code below, I define a new narrower environment to avoid interference.

\setupwhitespace[medium]

\definenarrower
  [sectionnarrower]
  [left=2em,
   default=left]

\setuphead
  [subsection]
  [
    margin=2em,
    beforesection={\startsectionnarrower},
    aftersection={\stopsectionnarrower},
  ]

\setuphead
  [subsubsection]
  [
    margin=4em,
    beforesection={\startsectionnarrower},
    aftersection={\stopsectionnarrower},
  ]

With this setup, you don't need to add any commands in the main document.

\starttext

\startsection
    [title={A section}]

  \input ward

  \startsubsection
      [title={A subsection}]

    \input ward

    \startsubsubsection
        [title={A subsubsection}]

      \input ward

    \stopsubsubsection

    \input ward

  \stopsubsection

  \input ward
\stopsection

\stoptext

enter image description here

To get section numbers in the margin, add

\setuphead[alternative=inmargin]

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .