Tx · LaTeX & TikZ

How to Add a Left Indent to Section Headings in LaTeX

Published By the 9to5Science editorial team

At a glance

  1. 1. Load titlesec

    Add the titlesec package to your document preamble.

  2. 2. Set heading indents

    Use titlespacing to give section and subsection headings a positive left offset.

  3. 3. Compile and adjust

    Change the lengths to suit your layout; this shifts headings, not the text block.

To shift \section and \subsection headings to the right, set their left spacing with the titlesec package. This indents the headings while leaving the page margins and the body text width unchanged.

Minimal working example

\documentclass{article}
\usepackage{titlesec}

% Arguments: heading, left indent, space before, space after
\titlespacing*{\section}{1em}{3.5ex plus 1ex minus .2ex}{2.3ex plus .2ex}
\titlespacing*{\subsection}{2em}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}

\begin{document}

\section{An indented section}
The paragraph starts at the normal text margin.

\subsection{An indented subsection}
This paragraph also starts at the normal text margin.

\end{document}

The first argument after the heading command is the left offset. Here, section headings move right by 1em and subsection headings by 2em. Change those values to adjust the indent. The remaining two arguments control the vertical space before and after each heading.

The example uses \titlespacing*. The star prevents indentation of the paragraph immediately following the heading. It does not control the heading’s left offset. If you want the normal paragraph indent after a heading, use the unstarred form, such as \titlespacing{\section}{1em}{...}{...}.

What the settings change

The titlespacing command has this general form:

\titlespacing*{command}{left}{before-sep}{after-sep}
  • command is the heading level, such as \section or \subsection.
  • left is the horizontal offset for the heading.
  • before-sep and after-sep set vertical spacing around it.

A positive left value moves the heading right; a negative value moves it left. The setting applies to numbered and starred forms of the heading, such as \section and \section*.

Indent the text too, if needed

Changing the heading’s left offset does not indent the paragraphs that follow. If you want the heading and its content to share a left edge, use a layout environment or adjust the text block itself; those changes affect more than the heading. Avoid changing \leftmargin directly for this purpose, since it is not the standard way to format section titles.

Common mistakes

  • Changing the page margin instead: Page-margin settings shift the whole text block, including paragraphs. Use the left argument of \titlespacing when only headings should move.
  • Treating the star as the indent setting: The star controls indentation of the paragraph after the title. The left offset is still the second argument after the heading command.
  • Forgetting to load titlesec: The \titlespacing command is provided by that package. Put \usepackage{titlesec} in the preamble, before \begin{document}.
  • Using titlesec with a class that defines its own heading layout: Classes such as memoir and KOMA-Script provide their own section-formatting interfaces. Prefer the class’s documented commands rather than combining its system with titlesec.

References

  1. The titlesec package documentation

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.