1

First off, I realise there are a lot of questions on this topic, and I've had an extensive look at finding an answer to my question, but haven't found one; if there is a duplicate on this site, my sincere apologies. Now for the actual question...

I would like to create an enumerated list in a way that I can choose the label and then have a hyperref reference to this label. The accepted answer on this SE question here almost does exactly what I want. The answer gives the following MWE.

\documentclass{article}
\usepackage{enumitem}
\begin{document}
\begin{enumerate}[label=\textbf{S.\arabic*}]
\item a
\item \label{l} b
\item c. goto \ref{l}
\end{enumerate}
\end{document}

Now, I would like to do exactly this, but I don't want to have to write label=... each time. Previously, I had used something like

\newcommand{\alphanumbering}{\renewcommand{\labelenumi}{(\textit{\alph{enumi}})}}

and then just prior to typing begin{enumerate} I would type \alphanumbering. When I use \ref, however, I just get the counter (which is enumi?), and I can't even use something like \alph{\ref{1}}.

I'd then like to extend this further, to write something like \alphaarabicnumbering before enumerate, where

\newcommand{\alphaarabicnumbering}{
    \renewcommand{\labelenumi} {(\textit{\alph{enumi}})}
    \renewcommand{\labelenumii}{\arabic{enumii}.} }

This then gives a list with first level (a), (b), ... and second level 1., 2., .... For example,

(a) foo
    1. bar
    2. foobar

I'd like to reference "foobar" as (a.2), and other lines similarly. (Note that a naive reference would be (a)2, which is not what I want.)

For reference, see also this SE question.

  • 1
    You can use \setlist to change the default behaviour of the list, and \newlist to define your own list types. See the documentation. – Ulrike Fischer Jun 26 '17 at 14:28
  • Someone had asked for clarification on the (a.2) referencing, but has now deleted their comment; I've added clarification anyway. – Sam T Jun 26 '17 at 14:39
  • Your posting contains (at least) two separate, and fairly unrelated, queries. This site works best if each query contains only one (main) question. Please consider editing your posting to (a) remove all stuff not related to the first main question (which, I gather, is about automating the label=... material), and (b) posting a separate, new query in which you bring up the remaining material from the original query. – Mico Jun 26 '17 at 14:40
  • I suppose one could consider it as two (highly-related) questions, but if so then really one is a sub-question of the other: I want to be able to reference in a certain way, but I merely gave a stepped description. The other option is that I'm misunderstanding TeX more than I realised: feel free to suggest which bits are unrelated, and I can edit the question for clarity! :) – Sam T Jun 26 '17 at 14:47
1

... I don't want to have to write label=... each time.

Since you're loading the enumitem package, you may want to make use of its \newlist and \setlist macros to create a custom enumerated environment that does the special labelling automatically. The solution is fully compatible with the hyperref package.

\documentclass{article}

\usepackage{enumitem}
\newlist{senum}{enumerate}{1} % create a new, 1-level enumerated environment
\setlist[senum]{label=\textbf{S.\arabic*}} % define the labels

\begin{document}
\begin{senum}
\item a
\item \label{x} b
\item c.\ goto \ref{x}
\end{senum}
\end{document}
  • I assume that by changing the 1 in \newlist, I can create a multilevel enumerated environment? How would I then define the labels? Alternatively, should I just define nested environments? – Sam T Jun 26 '17 at 14:41
  • 1
    @SamT - Indeed, you can define new lists up to 10 levels deep. For the syntax on how to modify the labels at various nesting depths, please see section 7 on pp. 10-11 of the user guide of the enumitem package. (Open a command prompt and type "texdoc enumitem" to lauch a copy of the package's user guide.) – Mico Jun 26 '17 at 14:52
  • After a bit of fiddling around, I've got it working exactly how I want it :) -- I'll add my own answer which gives a MWE, so that other people looking at this question can have some more detail. I've upvoted and accepted your answer, not mine, though! – Sam T Jun 26 '17 at 15:07
1

Here is a MWE to give a few more details. To those who are very familiar with TeX, Mico's answer and a brief glance at the documentation (which has some examples, but not necessarily exactly what I want) will be sufficient, but for those like myself we need to do a little bit of testing to see exactly what's going on! Here it is below.

\documentclass[]{article}
\usepackage{enumitem}
\newlist{list1}{enumerate}{2}
\setlist[list1,1]{label=\arabic{list1i},ref=\arabic{list1i}}
\setlist[list1,2]{label=\alph{list1ii},ref=(\arabic{list1i}.\alph{list1ii})}
\begin{document}
\begin{list1}
    \item \label{1} ITEM 1
    \item \label{2} ITEM 2
    \begin{list1}
        \item \label{3} ITEM (2.a)
    \end{list1}
\end{list1}
\ref{1} \ref{2} \ref{3}
\end{document}
  • Glad you found a solution that works for you. Just for completeness: the two \setlist instruction may written a bit more compactly as \setlist[list1,1]{label=\arabic{*}} and \setlist[list1,2]{label=\alph{*}, ref=(\thelist1i.\alph{*})}, respectively. – Mico Jun 27 '17 at 5:17
  • Ah, you are indeed correct! Moreover, I can write \arabic*, dropping {}. Thanks very much – Sam T Jun 27 '17 at 8:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.