Enumeration in powers of 2
Examples with xfp
or pgfmath
are shown below. Note that the enumi
counter is for the outermost level, if this is a nested list you need enumii
/enumiii
/enumiv
, depending on the level of nesting.
\documentclass{article}
\usepackage{enumitem}
\usepackage{xfp}
\usepackage{pgfmath}
\begin{document}
\begin{enumerate}[label={\protect\fpeval{2^(\value{enumi}-1)}.}]
\item
foo
\item
bar
\item
baz
\item
foo
\item
bar
\item
baz
\item
foo
\item
bar
\item
baz
\end{enumerate}
\begin{enumerate}[label={\protect\pgfmathparse{int(2^(\value{enumi}-1))}\protect\pgfmathresult.}]
\item
foo
\item
bar
\item
baz
\item
foo
\item
bar
\item
baz
\item
foo
\item
bar
\item
baz
\end{enumerate}
\end{document}
No other package used, only enumitem
's way of adding enumerate counter and evaluating with \numexpr
, defining a new list in order to keep the regular enumerate
list clean.
\documentclass{article}
\usepackage{enumitem}
\newcounter{powercntr}
\makeatletter
\DeclareRobustCommand{\poweroftwocalc}[1]{%
\ifnum1<\value{#1}%
\setcounter{powercntr}{\numexpr\c@powercntr*2}
\fi
}
\def\poweroftwo#1{\poweroftwocalc{#1}\expandafter\@poweroftwo\csname the#1\endcsname}
\def\@poweroftwo#1{\thepowercntr}
\AddEnumerateCounter{\poweroftwo}{\@poweroftwo}{4096}
\newlist{powerlist}{enumerate}{1}
\setlist[powerlist,1]{before=\setcounter{powercntr}{1}}
\makeatother
\begin{document}
\begin{powerlist}[label={\poweroftwo*}]
\item And
\item Now
\item For
\item Something
\item Completely
\item Different
\item Was
\item Said
\item Very
\item Frequently
\item In
\item Monty
\item Python's
\item Flying
\item Circus
\end{powerlist}
\end{document}
No other packages used, no e-TeX needed. Basically a rip-off of @ChristianHupfer's idea.
\documentclass{article}
\usepackage{enumitem}
\newcounter{powercntr}
\DeclareRobustCommand{\updatepowercntr}[1]%
{\arabic{powercntr}\addtocounter{powercntr}{\value{powercntr}}}
\newlist{powerlist}{enumerate}{1}
\setlist[powerlist,1]{before=\setcounter{powercntr}{1}}
\begin{document}
\begin{powerlist}[label={\updatepowercntr*}]
\item And
\item Now
\item For
\item Something
\item Completely
\item Different
\item Was
\item Said
\item Very
\item Frequently
\item In
\item Monty
\item Python's
\item Flying
\item Circus
\end{powerlist}
\end{document}