[Tex/LaTex] Add margin left to \section and \subsection

formattingsectioningsections-paragraphs

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?

Best Answer

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

Related Question