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}
jemp
  • 519
  • 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 Jul 12 '11 at 00: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 Jul 12 '11 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 Jul 12 '11 at 10:18

1 Answers1

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

przemoc
  • 2,142
  • 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 Jul 12 '11 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 Jul 12 '11 at 10:47
  • A possible solution is setting label=\hspace{-\labelsep}(\alph*) in level 2. – Javier Bezos Jul 12 '11 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 Jul 13 '11 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 Jul 14 '11 at 00:05
  • @przemoc Well, I did actually read your code and the specs. I'm a bit pressed for time now, though, and I can't say I was able to digest everything I found there, so I came running here ;) Still, I do get the point about the default widest value. The purpose of my last comment was that I thought there might be a way of making enumitem somehow choose the widest label from those available, so that in a list consisting of (1)(a) and (b), the spaces between the labels and the items would be automatically optimized for (b), while in (1)(a)–(m), the optimization would be for (m). – jemp Jul 14 '11 at 11:33
  • @przemoc Oh, and yes, I'm nitpicking ;) Anyway, thank you for your help and patience. – jemp Jul 14 '11 at 11:35
  • @jemp: We all usually work under pressure, hurried by deadlines, etc., so it's not like I do not understand you here, but enumitem doc is not that long, so skimming it is not overly time consuming. :) Ad rem: It is a good practice to have constant indentation scheme across whole document, thus I would rather avoid customizing widest for each enum using letters. OTOH I can agree that sometimes it's not that easy to get visually appealing result in any case. This is why I prefer here right alignment in second-level preceded by non-0 labelsep, because then it looks always good IMO, YMMV. – przemoc Jul 14 '11 at 11:51
  • @jemp: m just used to be the widest letter, but it's not mandatory nowadays (although this unspoken rule is rather rarely broken and only in some fancy fonts). You may also consider using fixed-size fonts for enum labels, then your label spacing problem should completely disappear. – przemoc Jul 14 '11 at 11:56