6

Is there a way to have a enumerate environment that increment the counter every three item?

I already see this question: Enumerate pattern: 1, 1, 2, 2, 3, 3, ... , etc

but I'm looking for something more simple.

this should work but i don't want to set the counter every item:

\begin{enumerate}
    \item First Item
    \setcounter{enumi}{0}
    \item Another first item
    \setcounter{enumi}{0}
    \item latest first item
    \item Second Item
    \setcounter{enumi}{1}
    \item Another second item
    \setcounter{enumi}{1}
    \item latest second item
\end{enumerate}

I want something like this:

\begin{enumerateeachthree}
     \item First Item
     \item Another first item
     \item latest first item
     \item Second Item
     \item Another second item
     \item latest second item
\end{enumerateeachthree}

In both example the output must be: 1) First Item 1) Another first item 1) latest first item 2) Second Item 2) Another second item 2) latest second item

  • This is weird... are you sure they are all at "the same level", i.e., not "first item, two subitems; second item, two subitems, ..." – vonbrand Aug 7 '15 at 15:03
  • no no i want all the item at the same level – Doc Aug 7 '15 at 16:02
8

Here's a solution with enumitem, with the help of expl3 for the arithmetic:

\documentclass{article}
\usepackage{enumitem,xparse}

\ExplSyntaxOn
\DeclareExpandableDocumentCommand{\counterbythree}{m}
 {
  \doc_counter_by_three:c { c@#1 }
 }
\cs_new:Nn \doc_counter_by_three:N
 {
  \int_div_truncate:nn { #1 + 2 } { 3 }
 }
\cs_generate_variant:Nn \doc_counter_by_three:N { c }
\AddEnumerateCounter{\counterbythree}{\doc_counter_by_three:c}{0}
\ExplSyntaxOff

\newenvironment{enumerateeachthree}[1][]
 {\enumerate[label=\counterbythree*.]}
 {\endenumerate}

\begin{document}

\begin{enumerateeachthree}
\item First Item
\item Another first item
\item latest first item
\item Second Item
\item Another second item
\item latest second item
\item Third Item
\item Another third item
\item latest third item
\end{enumerateeachthree}

\end{document}

enter image description here

6

Without packages. I just define three versions of \item (\itemA, \itemB, and \itemC) two of which decrement the enumi counter before invoking the saved form of \item. They also redefine the next invocation of \item to the next variant.

To get the process rolling, I define the enumerateeachthree environment to set \item to \itemA before starting the traditional enumerate environment (this was EDITED, as the original solution redefined the enumerate environment, which is probably not ideal).

\documentclass{article}
\let\svitem\item
\def\itemA{\let\item\itemB\svitem}
\def\itemB{\let\item\itemC\addtocounter{enumi}{-1}\svitem}
\def\itemC{\let\item\itemA\addtocounter{enumi}{-1}\svitem}
\newenvironment{enumerateeachthree}{\let\item\itemA\enumerate}{\endenumerate}
\begin{document}
\begin{enumerateeachthree}
     \item First Item
     \item Another first item
     \item latest first item
     \item Second Item
     \item Another second item
     \item latest second item
\end{enumerateeachthree}
\end{document}

enter image description here


FOLLOW UP:

While the OP indicates that, for his/her code, this approach fails to keep proper track of the counter (and I respect that deficiency), I would just like to let the reader know that there must be more to the issue, as the following MWE works just fine inside a footnoted minipage.

\documentclass{article}
\usepackage{lipsum}
\let\svitem\item
\def\itemA{\let\item\itemB\svitem}
\def\itemB{\let\item\itemC\addtocounter{enumi}{-1}\svitem}
\def\itemC{\let\item\itemA\addtocounter{enumi}{-1}\svitem}
\newenvironment{enumerateeachthree}{\let\item\itemA\enumerate}{\endenumerate}
\begin{document}
\lipsum[4]
\begin{minipage}{3in}
\lipsum[4]
\footnote{Footnote
\begin{enumerateeachthree}
     \item First Item
     \item Another first item
     \item latest first item
     \item Second Item
     \item Another second item
     \item latest second item
\end{enumerateeachthree}
}
\end{minipage}
\end{document}

enter image description here

  • After the first three item the counter goes crazy and it shows 0, 0, -1, -2, -1 ecc ecc. It's a problem with my code (two of the three items are in a minipage inside a footnote). Thanks anyway :) – Doc Aug 7 '15 at 8:33

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.