[Tex/LaTex] Customizing indentation in section and subsection headings

indentationsectioning

I would like to be able to \renewcommand\section and get LaTeX to format the section and subsection headings so that their numbers are left-justified, and the headings are exactly above the paragraph indentation:

1          Section title
1.1        Subsection title
           Start of paragraph

I found advice to change the indentation of the Section title like so:

\renewcommand\section{%
 \def\@seccntformat##1{\csname the##1\endcsname\hspace{_____}}
 \@startsection{your}{parameters}{here}...
}

If I insert 1in in the \hspace command, I get exactly one inch from the end of the section number. I want 1 inch from the left margin, so something like \hspace{1in \@minus \width\csname}, or something like that. That command doesn't work, but at least shows my intention.

Best Answer

Which document class do you use? Here is an example with scrartlc

\documentclass{scrartcl}
\usepackage{lipsum}
\renewcommand*{\othersectionlevelsformat}[3]{%
\llap{#3\autodot\enskip}}
\begin{document}
\section{foo}
\lipsum[1]
\section{bar}
\subsection{foo bar}
\lipsum[1]
\end{document}

By using a standard class you can use the package titlesec

\documentclass{article}
\usepackage{titlesec}
\titlelabel{\llap{\thetitle\quad}}
\usepackage{lipsum}
\begin{document}
\section{foo}
\lipsum[1]
\section{bar}
\subsection{foo bar}
\lipsum[1]
\end{document}

The result:

enter image description here

In relation to your comment:

\documentclass{article}
\usepackage{titlesec}
%1inch=25,4mm
\titlelabel{\llap{\makebox[1cm][l]{\thetitle}}\hspace*{25.4mm}}
%\usepackage{indentfirst}
\usepackage{lipsum}
\usepackage{showframe}
\begin{document}
\section{foo}
\hspace*{25.4mm}\lipsum[1]
\section{bar}
\subsection{foo bar}
\lipsum[1]
\end{document}

The package indentfirst is a possibility if every indent should be 1inch. I think 1inch is to big.

Related Question