18

I have a corollary with a number of parts whose parts need to be referenced individually later on, so something like:

\begin{cor}\label{cor}
   \begin{enumerate}
       \item Part one \label{partone}
       \item Part two \label{parttwo}
   \end{enumerate}
\end{cor}

Ideally, I want \ref{partone} to produce 2.1 (supposing it were Corollary 2 for the sake of argument), but, of course, \ref{partone} gives 1, as it's referencing the enumi counter.

Is there a way to get \ref to somehow combine the enumi and cor counters?

4 Answers 4

14

This can also be achieved by using the enumitem package:

\documentclass{article}
\usepackage{amsthm}
\usepackage{enumitem}

\newtheorem{cor}{Corolary}

\begin{document}

\begin{cor}\label{cor}
   \begin{enumerate}[label={\thecor.\arabic*}]
       \item Part one \label{partone}
       \item Part two \label{parttwo}
   \end{enumerate}
\end{cor}
As we see in part~\ref{partone}

\end{document}
4
  • 2
    Shouldn't it be [ref={\thecor.\arabic*}]? I understand that holyland only wants the reference to be changed, not the label of the item itself. Commented Mar 15, 2011 at 0:00
  • @Michael Ummels: if the change should only affect the reference, then yes, [ref={\thecor.\arabic*}] would do the job; however, that would produce an odd result, since formally you would have a reference, for example, 1.2 to an object numbered as simply 2. For the sake of consistency I suggested the change to both the label and the reference. Commented Mar 15, 2011 at 0:32
  • 1
    I agree. Maybe, it is better to put the item number in parentheses, so the label would just say (1) and the reference would be e.g. to Theorem 2 (1). This could be done by saying [label={(\arabic*)},ref={\thecor~(\arabic*)}], I suppose. Commented Mar 15, 2011 at 12:30
  • Michael's second suggestion is what I was after. We'll see what people say about consistency between labels and references (if anyone notices). My feeling is that having the labels appear as 2.1.1, 2.1.2, etc looks really cluttered, especially with 'Corollary 2.1' right above.
    – hoyland
    Commented Mar 15, 2011 at 23:54
4

i was going to ask the exact same question. i found the solutions given here too complicated, i especially didnt want to get new packages for such a simple job. so i kept on reading and i am now completely satisfied with this solution:

\hyperref[partone]{\ref*{cor}.\ref*{partone}}

2
  • 2
    This is great! Just to add some clarification to the answer: this command creates a reference and should be used where you'd normally put your ref. The [partone] tells you where the link should point to, the \ref*{cor} produces the number of the corollary and the \ref*{partone} produces the "subnumber" in the enumeration. You can also replace the first \ref* by \cref* to get something like "Corollary 2.1" automatically.
    – Josh Hunt
    Commented Sep 5, 2019 at 11:47
  • This looks like it could be even more flexible than @Michael-Ummels's second suggestion that the OP @hoyland was after. But I guess this solution creates a reference only to the label partone. Is that right? And if so, is there any easier way to create a reference for all items in the enumerate environment using just one line of code, rather than appending the above code to every individual item? Commented Jul 10 at 17:34
3

You can use the chngcntr package to make the enumi counter depend on your cor counter. If you do this within the corollary environment, it won't affect other enumerate environments.

\documentclass{article}
\usepackage{amsthm}
\newtheorem{cor}{Corollary}
\usepackage{chngcntr}

\begin{document}

\begin{cor}{My Cor}\label{mycor}
  \counterwithin{enumi}{cor}
  \begin{enumerate}
    \item An item \label{part1}
    \item Another one \label{part2}
  \end{enumerate}
\end{cor}

In Part~\ref{part1} of the the corollary\ldots

\begin{enumerate}
  \item An item \label{outside}
\end{enumerate}
This is a reference to Item~\ref{outside} that is outside the corollary.
\end{document}

Even simpler, and without using the chngcntr package, you can simply redefine \theenumi within the cor environment:

\begin{cor}{My Cor}\label{mycor}
  \renewcommand{\theenumi}{\thecor.\arabic{enumi}}
  \begin{enumerate}
    \item An item \label{part1}
    \item Another one \label{part2}
  \end{enumerate}
\end{cor}
4
  • 2
    Whoever downvoted this answer: is there something wrong with the solution that I missed?
    – Alan Munn
    Commented Mar 15, 2011 at 1:09
  • It does get the job done, as far as I can tell. I'm inclined to think Gonzalo's solution is more elegant or at least allows for more flexibility. (What I was actually after was Michael's comment to Gonzalo's answer.)
    – hoyland
    Commented Mar 15, 2011 at 23:48
  • @hoyland I see. But since your question didn't actually state that... Anyway, I don't particularly care about votes, (I certainly don't need the reputation) but you may want to take a look at this for some other ideas on downvoting: Down Vote Etiquette
    – Alan Munn
    Commented Mar 16, 2011 at 1:37
  • Ah, I wasn't the down vote; I was just speculating. I have no idea what the objection could have been other than someone thinking it didn't answer the question, since people seemed to read it different ways.
    – hoyland
    Commented Mar 16, 2011 at 4:18
0

I am going to slightly modify the approach with enuitem above. I am also going to make the following assumptions:

  • All theorem-like environments have the same counter
  • The counter is called \thethm

First I define a new list in the preabmle (after calling the enuitem package) called thmenum

\newlist{thmenum}{enumerate}{1}
\setlist[thmenum, 1]{label=(\arabic*), ref=\thethm (\arabic*)}

So if you have a theorem environment you can do this:

\begin{thm}
\label{thm:some_theorem}
\begin{thmenum}
  \item Statement 1\label{thm:some_theorem:somestatement}
  \item Statement 2\label{thm:some_theorem:someotherstatement}
\end{thmenum}
\end{theorem}
....
\ref{thm:some_theorem:somestatement}

will produce a reference of the form 1.1(1), but the labels will be (1), (2), ...

You must log in to answer this question.

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