# How can I align section titles and list environments in the left margin?

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.

-
Welcome to TeX.sx! Usually, we don't put a greeting or a "thank you" in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Upvoting is the preferred way here to say "thank you" to users who helped you. – Werner Oct 30 '11 at 17:39
Note that in traditional LaTeX documents the sectional numbering is not boxed and has a fixed separation between the number and the title (say \quad). You want to forego this and have a left-aligned number within a boxed width of say <width> and then have the same for any lists? What about the period . in your enumerated list? That doesn't align in a similar way to the itemized list or the sectional numbers. – Werner Oct 30 '11 at 17:43

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.

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}

-
Thank you so much, I didn't think it would be this simple! You response is much appreciated! – user2473 Oct 30 '11 at 18:15
@cmhughes Thank ou for your answer. Using your example, the numberless section titles are gone; how do I bring them back? – blackened Sep 15 at 22:04