3

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}
3
  • Your MWE is not working, so it should be corrected. Also you're abusing \Large as it is not an environment (it just works thanks to \endLarge slipping w/o an error). Not sure whether you're aware of it, so brought it up.
    – przemoc
    Commented Jul 12, 2011 at 0:44
  • @przemoc Thanks for pointing it out to me – I wasn't aware I was such a LaTeX abuser ;) I'm a novice and still have A LOT to learn! Anyway, I've now made the necessary corrections to the code, so now it should work. Sorry that it was not a working example; originally, it was fine, but then I made a few infelicitous modifications when writing this questions.
    – jemp
    Commented Jul 12, 2011 at 10:01
  • Welcome in amazing (Le)TeX world then. :) To get better understanding of your \Large abuse you should read answer to How to use \Large et al. question.
    – przemoc
    Commented Jul 12, 2011 at 10:18

1 Answer 1

3

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

9
  • Thank you for taking time to write this code! It comes very close to what I was aiming for. The only thing I would like to change is the space between e.g. (1) and (a) that seems to be the default result of list nesting. In other words, I'd like to get "(1)(a)" instead of "(1) (a)". As you suggested, I'll consult the enumitem documentation and try to find a solution there :)
    – jemp
    Commented Jul 12, 2011 at 10:15
  • @jemp: I've added what you're looking for, but mind this solution has clearly visible drawback if you have items at both 1st and 2nd level in one enumerate.
    – przemoc
    Commented Jul 12, 2011 at 10:47
  • A possible solution is setting label=\hspace{-\labelsep}(\alph*) in level 2. Commented Jul 12, 2011 at 17:30
  • @przemoc Thank you! That helps a lot, though there seems to be some kind of side effect here – the space between a level 2 label and its item is greater than the space between a level 1 label and its item, even if these labels sit in different enumerate environments. (See (1)(a) and (3).) @Javier Bezos Thank you for your suggestion. I'm not sure if I have applied it correctly because, after adding it to przemoc's code, I noticed that the adjacent brackets in (1)(a) collapsed. I wish I had more time right now to experiment with the settings as it seems the solution is not so far away :)
    – jemp
    Commented Jul 13, 2011 at 23:55
  • @jemp: If you would read docs and my code, you would understand why it is different. You wanted (a) to be just after (1), so I had to change alignment from right to left. Remember enum should look good even when there are many items - it's the exact reason why I showed you the longest m case which is used as widest option by default. If you're sure that you'll never get m, then set it to e.g. d or g.
    – przemoc
    Commented Jul 14, 2011 at 0:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .