Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have a weird numbering problem in a manuscript that uses sequentially numbered text examples. When an example demonstrates something which is e.g. wrong and later to be corrected they have suffixes a, b, and so on. In between it happens that there is text and possibly other examples which continues the original numbering, e.g:

(1) ... example ...

... text ...

(2a) ... bad example ...

... enlightening text and example:

(3) ... example ...

... after which we might return to the earlier bad example (2a) and show the correction

(2b) ... good example ...

... back to normal with more examples:

(4) ... example ...

I was asked how one would do this in a smart way in LaTeX. I have tried using the enumitem package as follows, but ran into trouble:

\documentclass{article}

\usepackage{enumitem}

\newlist{examples}{enumerate}{1}
\setlist[examples]{label=(\arabic*)}
\newlist{subexamples}{enumerate}{1}

\begin{document}
First an example, which we call 1.
\begin{examples}
  \item example
\end{examples}
Then a bad example which we would like to call 2a: 
\addtocounter{examplesi}{1}
\begin{subexamples}[series=aname, label=(\theexamplesi\alph*)]
  \item example
\end{subexamples}
We learn something new in examples 3 and 4 (with wrong labels):
\begin{examples}[resume]
  \item example
  \item example
\end{examples}
And we get back to the bad example, which should be 2b: 
\begin{subexamples}[resume*=aname]
  \item example
\end{subexamples}

\end{document}

The above example produces the labels 1, 2a, 2, 3, 3b. The goal was 1, 2a, 3, 4, 2b.

One should be able to reference the individual items, and it should be flexible enough to have more than a single "hanging" example...

share|improve this question
    
Welcome to TeX.sx! You don't have to sign with your name since it automatically appears in the lower right corner of your post. –  Werner Jul 31 '12 at 17:56
    
Please don't cross-post questions. Rather flag them for migration. –  Werner Jul 31 '12 at 17:58
    
Sorry, I'm not too well informed about the interaction between these fora. –  Stefan Jul 31 '12 at 18:00
    
Don't worry. Most new-comers are unfamiliar with the inter-relationship between networks on Stack Exchange. You can delete your post on StackOverflow. Alternatively, it may be closed as "off topic" there, or migrated here where it will also be closed as a "duplicate" of this question. Regardless, you should synchronise your two accounts by using the same OpenID (at the moment you have two separate accounts, according to Stack Exchange; one for Stack Overflow and one for TeX - LaTeX). –  Werner Jul 31 '12 at 18:04
    
If I close it on StackOverflow, will it still be closed here? Is this not a more relevant place to ask the question? And how do I close a question? ... never mind, deleted it on SO. Hope this will stay open then... –  Stefan Jul 31 '12 at 18:09
show 3 more comments

1 Answer

Well, I found one way to do it; I wouldn't call it satisfactory but it works. The cons are: you can't mix examples with suffixes and examples without in a single list, and the siffixes a, b, ... are 'hard coded' whereas the main counter is 'automatic'. Also, I would think it could be prettier as the referencing is slightly messy. Here goes:

\documentclass{article}

\usepackage{enumitem}
\newlist{examples}{enumerate}{1}
\setlist[examples]{label=(\arabic*), ref=\arabic*, resume}

\begin{document}

\section{On numbered examples}
First, an example:
\begin{examples}
   \item\label{first} \dots example \dots
\end{examples}
This can be referenced as expected: check out (\ref{first}).
Now, a second example which we can elaborate on later is
\begin{examples}[label=(\arabic*a), ref=\arabic*]
   \item\label{second} \dots example \dots
\end{examples}
The suffix in (\ref{second}a) hard coded as \verb+label=(\arabic*a)+
in the options for this one example environment.

We learn something new in examples 3 and 4, and use the
environment as is:
\begin{examples}
   \item example
   \item example
\end{examples}
And we get back to previous example in examples 2b and 2c:
\begin{examples}
  \item[(\ref{second}b)] \dots example \dots
  \item[(\ref{second}c)] \dots example \dots
\end{examples}
Since \verb+\item+ is used with \verb+[]+ the counter is not
incremented. These are referenced as e.g. \verb+(\ref{second}b)+.
And we test that the counter is as it should be:
\begin{examples}
   \item \dots example \dots
\end{examples}

\end{document}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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