12

I need to typeset a list like the following:

  1. item 1

  2. item 2

  3. item 3

4-6. The same as previous ones

  1. Something else

Currently, I have typeset it using description environment as

\documentclass{article}
\begin{document}
   \begin{description}
      \item[1.] item 1
      \item[2.] item 2
      \item[3.] item 3
      \item[4-6.] The same as previous ones
      \item[7.] Something else
   \end{description}
\end{document}

However, I wonder if this is possible using enumerate or something else which does the numbering itself. Is it possible to create this list using enumerate?

In other words, can we do some thing like this to get the desired output

\documentclass{article}
\begin{document}
   \begin{enumerate}
      \item item 1
      \item item 2
      \item item 3
      \item[4-6.] The same as previous ones
      \item Something else
   \end{enumerate}
\end{document}

or even using something like \item[len=3] The same as previous ones where by len, I mean the number of enumerative items after the current one.

  • Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – user31729 Feb 15 '15 at 12:34
  • \begin{enumerate} \item ...\end{enumerate} does not work ? Or should \item[4.-6.] automatically expand \item ...? – user31729 Feb 15 '15 at 12:36
  • @ChristianHupfer Thanks for your comment. I have modified it accordingly. However, I do not have a problem with this result, but just was curious if the same result is possible with enumerate or not? I have googled for an hour, but could not find it out, so decided to post it here. – Ali Shakiba Feb 15 '15 at 12:38
  • @ChristianHupfer The second case is the one I am seeking for. Is there any way for that? – Ali Shakiba Feb 15 '15 at 12:39
  • 2
    You can use \addtocounter{enumi}{3} just after \item[4-6.] The same as previous ones – karlkoeller Feb 15 '15 at 12:59
12

The only way I know to achieve what you want is to increment the enumi counter.

MWE:

\documentclass{article}
\begin{document}
   \begin{enumerate}
      \item item 1
      \item item 2
      \item item 3
      \item[4--6.] The same as previous ones\addtocounter{enumi}{3}
      \item Something else
   \end{enumerate}
\end{document} 

Output:

enter image description here

7

A version similar to Symbol 1's, but that doesn't require changing all the levels, since \@enumctr expands to the current counter.

The argument to \itemx is the number of items to unify.

\documentclass{article}
\usepackage{etoolbox}

\makeatletter
\newcounter{shakiba@temp}
\newcommand\itemx[1]{%
  \letcs\shakiba@save{the\@enumctr}
  \stepcounter{\@enumctr}%
  \protected@edef\shakiba@label{\csuse{the\@enumctr}--}
  \addtocounter{\@enumctr}{-1}%
  \addtocounter{\@enumctr}{#1}%
  \protected@edef\shakiba@label{\shakiba@label\csuse{the\@enumctr}}%
  \addtocounter{\@enumctr}{-1}
  \cslet{the\@enumctr}\shakiba@label
  \item
  \cslet{the\@enumctr}\shakiba@save
}
\makeatother

\begin{document}

\begin{enumerate}
\item item 1
\item item 2
  \begin{enumerate}
  \item subitem 2:1
  \itemx{5}\label{X} subitem 2:2-6
  \item subitem 2:7
  \end{enumerate}
\item item 3
\itemx{3}\label{Y} The same as previous ones
\item Something else
\end{enumerate}

References: \ref{X} and \ref{Y}

\end{document}

enter image description here

6

A very brute way, but no need to calculate counters yourself

\documentclass{article}

\def\itemx#1{
    \let\oldtheenumi\theenumi
    \let\oldtheenumii\theenumii
    \let\oldtheenumiii\theenumiii
    \let\oldtheenumiv\theenumiv
    \def\theenumi{\oldtheenumi-\addtocounter{enumi}{#1}\oldtheenumi}
    \def\theenumii{\oldtheenumii-\addtocounter{enumii}{#1}\oldtheenumii}
    \def\theenumiii{\oldtheenumiii-\addtocounter{enumiii}{#1}\oldtheenumiii}
    \def\theenumiv{\oldtheenumiv-\addtocounter{enumiv}{#1}\oldtheenumiv}
    \item
    \let\theenumi\oldtheenumi
    \let\theenumii\oldtheenumii
    \let\theenumiii\oldtheenumiii
    \let\theenumiv\oldtheenumiv
}

\begin{document}
    \begin{enumerate}
        \item item 1
        \item item 2
        \begin{enumerate}
            \item subitem 2:1
            \itemx5 subitem 2:2-6
            \item subitem 2:7
        \end{enumerate}
        \item item 3
        \itemx3 The same as previous ones
        \item Something else
    \end{enumerate}
\end{document}

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.