Solution 1) The most simple way consists in \usepackage{titlesec}
and its command \titleformat
\titlespacing
command.
Option 1 If you want an hard-coded number, you will have to use the starred versions of the sectioning commands and the MWE is :
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[vmargin=25mm,right=25mm,left=50mm,verbose=false]{geometry}
\usepackage{blindtext} % for demonstration only
\usepackage{titlesec}
\titlespacing*{\section}{-5em}{3.5ex plus -1ex minus -.2ex}{2.3ex plus .2ex}
\titlespacing*{\subsection}{-3em}{3.25ex plus -1ex minus -.2ex}{1.5ex plus .2ex}
\titlespacing*{\subsubsection}{-1em}{3.25ex plus -1ex minus -.2ex}{1.5ex plus .2ex}
\begin{document}
\section*{Header one}
\blindtext
\subsection*{Header two}
\blindtext
\subsubsection*{Header three}
\blindtext
\end{document}
where the lengths used are the default values for article
class.
Result:
Option 2 If oppositely you want a variable caption and an automatically incremented number, you will also use (i) the explicit
option of the package, (ii) an additional counter (iii) \titleformat
to put this number after the caption,
The code becomes:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[vmargin=25mm,right=25mm,left=50mm,verbose=false]{geometry}
\usepackage{blindtext} % for demonstration only
\usepackage[explicit]{titlesec}
\newcounter{flatnum}
\titleformat{\section}[hang]{\normalfont\bfseries\Large}{\relax}{0pt}{\stepcounter{flatnum} #1 \theflatnum}
\titleformat{\subsection}[hang]{\normalfont\bfseries\large}{\relax}{0pt}{\stepcounter{flatnum} #1 \theflatnum}
\titleformat{\subsubsection}[hang]{\normalfont\bfseries\normalsize}{\relax}{0pt}{\stepcounter{flatnum} #1 \theflatnum}
\titlespacing*{\section}{-5em}{3.5ex plus -1ex minus -.2ex}{2.3ex plus .2ex}
\titlespacing*{\subsection}{-3em}{3.25ex plus -1ex minus -.2ex}{1.5ex plus .2ex}
\titlespacing*{\subsubsection}{-1em}{3.25ex plus -1ex minus -.2ex}{1.5ex plus .2ex}
\begin{document}
\section{Section}
\phantomsection
\blindtext
\subsection{Subsection}
\blindtext
\subsubsection{Subsubsection}
\blindtext
\end{document}
where the styles ans lengths used are the default values for article
class.
Result:
Solution 2) A more involved solution, but more compatible, will use \usepackage{etoolbox}
and its command \patchcmd
to change the spacings in the corresponding \@startsection
-s.
To know which is the default setting, look in latex.tex
( or .ltx
), or simpler put \meaning\section
and \meaning\subsection
etc. in your body text.
For the explanation of this command you'd have look to the accepted answer of this question