Add margin left to \section and \subsection

2,713

For standard classes (not KOMA script classes as leandriis has pointed out) you can use the titlesec package to change the format and spacing of sections, subsections and so on. See page 4 for an explanation of \titleformat and \titlespacing and their optional arguments which I have not shown here for simplicity.

I have changed the <left> argument of the \titlespacing command to an arbitry value of 1em (which is usually 0). Change it however you want. The other values in the code below are taken from subsection 9.2. Standard Classes on page 23 and should be the values usually used by LaTeX.

The example below indents sections. Indenting subsections and subsubsections works in the same way.

\documentclass{article}

\usepackage{titlesec}

%\titleformat
%   {\section} % <command>
%   {\normalfont\Large\bfseries} % <format>
%   {\thesection} % <label>
%   {1em} % <sep>
%   {} % <before-code>

\titlespacing* % starred version: first paragraph is not indented
    {\section} % <command>
    {1em} % <left>
    {3.5ex plus 1ex minus .2ex} % <before-sep>
    {2.3ex plus .2ex} % <after-sep>


\usepackage{blindtext}

\begin{document}
    \section{Test}
    \blindtext
\end{document}

enter image description here

Share:
2,713

Related videos on Youtube

Lebyproc
Author by

Lebyproc

Updated on October 07, 2020

Comments

  • Lebyproc
    Lebyproc over 2 years

    I am looking for a way to change the margin form the left of the titles in LaTeX. I´ve added a picture to clarify my concern:

    How it should look like

    Is there a way, to change the margins of the titles of the sections, and only the titles, and not the entire paragraph below?

    • leandriis
      leandriis over 5 years
      Could you please add information on which document class you are using?
  • leandriis
    leandriis over 5 years
    Could you please add the document class you have used to test your solution? For me it works fine with standard classes, however due to the incompatibility with the titlesec package, it does not work with KOMA script classes. Information on how to indent sectioning heading using KOMA scriptclasses can be found for example here: tex.stackexchange.com/a/227936/134144
  • jakun
    jakun over 5 years
    @leandriis thanks for the hint. I have edited my answer.
  • jakun
    jakun over 5 years
    @Lebyproc I am glad if I could help. If the answer has answered your question please accept it.