[Tex/LaTex] How to align long labels in a list to the left margin

#enumeratehorizontal alignmentlists

I would like to create a list in LaTeX in which:
1. the longest label is aligned to the left margin,
2. the labels can be composite and look like "(1)(a)",
3. the labels, which can be of varying widths (e.g. one item is numbered "(1)(a)", the next one "(b)") are flush right,
4. the items are justified and are not indented.

Because nothing can beat a picture, here is the effect I would like to achieve:example of a list
Well, as you can see, I have managed to make such a list 🙂 The thing is, the solution I used involved a lot of manual setting, e.g. specyfing leftmargin in points (I used the enumitem package), which is not the most elegant way of doing things. I was wondering if it is possible to create such a list "automatically".

Since it's always good to give some code to work on, I can offer that:

\documentclass{article}
\usepackage{enumitem}
\newcounter{ex}
\newcounter{ex_alph}
\begin{document}
\section{Lorem ipsum}
\Large
\begin{enumerate}
\item[\refstepcounter{ex}(\theex)\stepcounter{ex_alph}(\alph{ex_alph})]Lorem ipsum\ldots
\item[\stepcounter{ex_alph}(\alph{ex_alph})]Lorem ipsum\ldots
\setcounter{ex_alph}{0}
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua\ldots
\end{enumerate}
\begin{enumerate}
\item[\refstepcounter{ex}(\theex)]Lorem ipsum\ldots
\end{enumerate}
\end{document}

Best Answer

Is below code result more or less what you are aiming for?

\documentclass{article}
\usepackage{lipsum}
\usepackage{enumitem}
% labelwidth = widest width; leftmargin = labelwidth + labelsep
\setenumerate{leftmargin=*}
\setenumerate[1]{label=(\arabic*),align=left} % widest=0
\setenumerate[2]{label=(\alph*)}              % widest=m
\newcommand*\lorem{Lorem ipsum\ldots}
\pagestyle{empty}
\begin{document}
\section{Lorem ipsum}
\Large
\begin{enumerate}
    \item
        \begin{enumerate}
            \item \lorem
            \item \lorem
        \end{enumerate}
        \ldots
        \begin{enumerate}[start=13]
            \item \lorem
        \end{enumerate}
    \item \lorem
\end{enumerate}
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua\ldots
\begin{enumerate}[resume]
    \item \lipsum[1]
\end{enumerate}
\ldots
\begin{enumerate}[start=9]
    \item \lorem
\end{enumerate}
\end{document}

example 1

It's worth to check enumitem documentation (texdoc enumitem), because its power is in decent configurability.

EDIT

If you change some lines as below

\setenumerate{leftmargin=*,labelsep=5pt}
...
\setenumerate[2]{label=(\alph*),align=left}   % widest=m
...
\begin{enumerate}[labelsep=0pt]
...
    \item \lorem {\small lacks proper alignment, as there is no per item labelsep}
\end{enumerate}
...

you'll get

example 2