[Tex/LaTex] How to align section titles and list environments in the left margin

indentationlistsmarginssectioning

I was wondering if you could help me with some alignment issues. I've search both here and Google but haven't really found a decent solution.

This is what I have (LaTeX default):

1 First section

  1. Apple
  2. Banana
  3. Cherry

1.1 First subsection

  - Foo
  - Bar

This is what I want:

  1  First section

  1. Apple
  2. Banana
  3. Cherry

1.1  First subsection

  -  Foo
  -  Bar

Notice how everything lines up in the margin in the second example. I think this makes the rhythm of the document flow much better.

A great example of what I want can be found in the documentation for the microtype package.

Best Answer

The solution below uses the enumitem package to customize the enumerate and itemize environments, and the titlesec package to customize the section and subsection headings.

screenshot

Note that I have loaded the geometry package with showframe=true to show where the page boundaries lie.

\documentclass{article}

\usepackage[showframe=true]{geometry}
\usepackage[explicit]{titlesec}
\usepackage{enumitem}

\titleformat{\section}%
            {\Large\bfseries}% format
            {\llap{% label
               \thesection\hskip 9pt}#1}%
            {0pt}% horizontal sep
            {}% before

\titleformat{\subsection}%
        {\bfseries}% format
        {\llap{% label
           \thesubsection\hskip 9pt}#1}%
        {0pt}% horizontal sep
        {}% before

\setlist[enumerate]{leftmargin=0mm}
\setlist[itemize]{leftmargin=0mm}

\begin{document}
\section{First section}
\begin{enumerate}
 \item apple
 \item orange
 \item grape
\end{enumerate}

\subsection{First subsection}
\begin{itemize}
 \item foo
 \item bar
 \item foobar
\end{itemize}
\end{document}