Tx · LaTeX & TikZ

How to Repeat Each Number in a LaTeX Enumerate List

Published By the 9to5Science editorial team

At a glance

  1. 1. Load enumitem

    Add the enumitem package to your preamble so you can customize the list label.

  2. 2. Check the counter parity

    Use the enumi counter to tell whether the current item is odd or even.

  3. 3. Display the pair number

    For odd items, divide the next integer by two; for even items, divide the current integer by two.

  4. 4. Apply the label

    Set the enumerate label to the custom command, then compile to check the sequence.

To make a LaTeX list display 1, 1, 2, 2, 3, 3, …, customize its label based on the current item number. The enumitem package lets you apply that label to an enumerate environment.

The example below is a complete document. It uses the first-level list counter, enumi, and gives odd and even items separate calculations. Each calculation divides an even integer by two, so the result does not depend on how TeX handles a non-integer quotient.

Complete example

\documentclass{article}
\usepackage{enumitem}

\newcommand{\pairlabel}{%
  \ifodd\value{enumi}
    \number\numexpr(\value{enumi}+1)/2\relax
  \else
    \number\numexpr\value{enumi}/2\relax
  \fi
}

\begin{document}

\begin{enumerate}[label=\pairlabel.]
  \item First item
  \item Second item
  \item Third item
  \item Fourth item
  \item Fifth item
  \item Sixth item
\end{enumerate}

\end{document}

The displayed labels are 1., 1., 2., 2., 3., and 3.. The package needed is enumitem; the other commands are provided by LaTeX and its underlying TeX engine.

How the label calculation works

LaTeX increments enumi once for each item, so its values are 1, 2, 3, 4, and so on. The command \ifodd\value{enumi} checks whether the current value is odd.

  • For an odd counter value, the command adds 1 and divides by 2. For example, item 3 displays (3+1)/2=2(3+1)/2=2.
  • For an even counter value, it divides the value by 2. For example, item 4 displays 4/2=24/2=2.

Thus items 1 and 2 both display 1, items 3 and 4 both display 2, and each subsequent pair follows the same pattern. The period in label=\pairlabel. is just punctuation; remove it if you want bare numbers.

Change the list level

The example customizes the outermost enumerate list, whose counter is enumi. For the next level of a nested list, use enumii instead. For example, replace each occurrence of enumi in the command with enumii when you apply the label to a second-level list. The counter name must match the list level being labeled.

References to list items

This changes the visible label, but the underlying counter still has its ordinary values. If you use \label and \ref, references may therefore show the original item number rather than the repeated display number.

If you want references to use the repeated number too, redefine the counter’s printed representation and use it for the list label:

\renewcommand{\theenumi}{\pairlabel}
\begin{enumerate}[label=\theenumi.]
  \item\label{item:first} First item
  \item Second item
\end{enumerate}

See item \ref{item:first}.

Compile twice so LaTeX can update cross-references. Use this change only when you want references to follow the custom numbering; otherwise, keep the simpler label-only version.

Common mistakes

  • Using \arabic* alone: That displays the ordinary counter sequence, not repeated numbers. The custom command must calculate the displayed value.
  • Referencing the wrong counter: enumi is the first list level; nested lists use enumii, enumiii, and so on.
  • Expecting \ref to change automatically: A custom enumitem label does not by itself change the counter representation used by references. Redefine \theenumi if references should show the repeated values.
  • Forgetting enumitem: The optional label=... setting in this example relies on the package, so include \usepackage{enumitem} in the preamble.

References

  1. The enumitem Package

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.