[Tex/LaTex] How to properly align three-level enumerate 1. 1.1. 1.1.1

#enumeratehorizontal alignmentmargins

I've created my environment, and modified the enumerate command:

\renewcommand{\labelenumi}{\arabic{enumi}.}
\renewcommand{\labelenumii}{\arabic{enumi}.\arabic{enumii}.}
\renewcommand{\labelenumiii}{\arabic{enumi}.\arabic{enumii}.\arabic{enumiii}.}

\newenvironment{packed_enum}{
\begin{enumerate}
\setlength{\itemsep}{1pt}
\setlength{\parskip}{0pt}
\setlength{\parsep}{0pt}
}{\end{enumerate}}

And this is what i get:

Latex Problem

The first two levels align properly (I've marked it with blue line), but the third level starts too much on the left (red line). Can You help me fix this?
I've tried something like this (also with changing labelsep to \leftmargin):

\renewcommand{\labelenumi}{\arabic{enumi}.}
\renewcommand{\labelenumii}{\arabic{enumi}.\arabic{enumii}.}
\renewcommand{\labelenumiii}{\setlength{\labelsep{5ex}\arabic{enumi}.\arabic{enumii}.\arabic{enumiii}.}

or this:

\renewcommand{\labelenumi}{\arabic{enumi}.}
\renewcommand{\labelenumii}{\arabic{enumi}.\arabic{enumii}.}
\renewcommand{\labelenumiii}{\hbox{\hspace{5ex}\arabic{enumi}.\arabic{enumii}.\arabic{enumiii}.}}

but neither helped.

Best Answer

With the help of enumitem

\newenvironment{packed_enum}{%
  \renewcommand{\labelenumi}{\arabic{enumi}.}%
  \renewcommand{\labelenumii}{\arabic{enumi}.\arabic{enumii}.}%
  \renewcommand{\labelenumiii}{\arabic{enumi}.\arabic{enumii}.\arabic{enumiii}.}%
  \begin{enumerate}[itemsep=1pt,parsep=0pt,leftmargin=*]%
  }{\end{enumerate}}

The option leftmargin=* ensures that the label is aligned with the surrounding text. Note that I also inserted all \renewcommands inside the \newenvironment to make the changes only locally.

MWE:

\documentclass{article}
\usepackage{enumitem}

\newenvironment{packed_enum}{%
  \renewcommand{\labelenumi}{\arabic{enumi}.}%
  \renewcommand{\labelenumii}{\arabic{enumi}.\arabic{enumii}.}%
  \renewcommand{\labelenumiii}{\arabic{enumi}.\arabic{enumii}.\arabic{enumiii}.}%
  \begin{enumerate}[itemsep=1pt,parsep=0pt,leftmargin=*]%
  }{\end{enumerate}}

\begin{document}

\begin{packed_enum}
  \item First level
  \begin{packed_enum}
    \item Second level
    \begin{packed_enum}
      \item Third level
    \end{packed_enum}
  \end{packed_enum}
\end{packed_enum}

\end{document} 

Output:

enter image description here

Related Question