6

I would like to make a list that went something like this:

(1a) item

(1b) item

(2a) item

(2b) item

...

(10a) item

(10b) item

and so on. Here is a minimal example of what I'm doing right now, which doesn't have the format I actually want, and which is also rather cumbersome, since I have to embed a list within another list.

\documentclass{article}
\usepackage{enumitem}
\begin{enumerate}[label=\arabic*]
\item
    \begin{enumerate}[label=\alph*.]
        \item item 1a
        \item item 1b
    \end{enumerate}
\item 
    \begin{enumerate}[label=\alph*.]
        \item item 2a
        \item item 2b
    \end{enumerate}
\end{enumerate}
1
  • 2
    So you always have a (Xa) (Xb) pair for every number X?
    – Werner
    Oct 26, 2016 at 22:28

3 Answers 3

6

Mark up with \itema and \itemb:

\documentclass{article}
\usepackage{enumitem}

\newenvironment{enumerateab}[1][]
 {\enumerate[label=\theEABII,before=\setcounter{EABI}{0},#1]}
 {\endenumerate}
\newcounter{EABI}
\newcounter{EABII}[EABI]
\makeatletter
\renewcommand{\theEABII}{\arabic{EABI}\@alph{\numexpr\c@EABII+1}}
\makeatother
\newcommand\itema{\stepcounter{EABI}\item}
\newcommand\itemb{\stepcounter{EABII}\item}

\begin{document}

\begin{enumerateab}
\itema item 1a
\itemb item 1b
\itema\label{foo} item 2a
\itemb item 2b
\end{enumerateab}

Item \ref{foo} is nice.

\end{document}

enter image description here

Alternative, if you always alternate “a” and “b”:

\documentclass{article}
\usepackage{enumitem}

\newenvironment{enumerateab}[1][]
 {\enumerate[label=\theEABII,before=\setcounter{EABI}{0}\itematrue,#1]%
  \let\latexitem\item\let\item\itemab}
 {\endenumerate}
\newif\ifitema
\newcounter{EABI}
\newcounter{EABII}[EABI]
\makeatletter
\renewcommand{\theEABII}{\arabic{EABI}\@alph{\numexpr\c@EABII+1}}
\makeatother

\newcommand\itemab{%
  \ifitema
    \stepcounter{EABI}\itemafalse\latexitem
  \else
    \stepcounter{EABII}\itematrue\latexitem
  \fi
}

\begin{document}

\begin{enumerateab}
\item item 1a
\item item 1b

\item\label{foo} item 2a
\item item 2b
\end{enumerateab}

Item \ref{foo} is nice.

\end{document}
4

Define your own representation

\documentclass{article}
\usepackage{enumitem}
\usepackage{xparse}
\ExplSyntaxOn\makeatletter
\NewDocumentCommand\arabicalph{ m }
{ \int_if_odd:nTF { \the\value{#1}} 
 { \int_eval:n {(\the\value{#1} + 1)/2 }a}
 { \int_eval:n {\the\value{#1} / 2 } b}}
\ExplSyntaxOff

\begin{document}


\begin{enumerate}[label=\arabicalph{enumi}]

        \item item 1a
        \item item 1b

        \item item 2a
        \item item 2b

\end{enumerate}
\end{document}

enter image description here

Remark: The syntax label= \arabicalph* doesn't work here, but it is now to late to try to find out why ...

2

Here is an implementation using an additional counter pairitem, and setting the representation of the item numbering manually:

enter image description here

\documentclass{article}

\newcounter{pairitem}
\newenvironment{pairenumerate}
  {\begin{enumerate}% Regular enumerate
     \let\olditem\item% Store \item
     \renewcommand{\theenumi}{\thepairitem\ifodd\value{enumi}a\else b\fi}% \item counter + reference
     \renewcommand{\labelenumi}{(\theenumi)}% Counter representation in list
     \setcounter{pairitem}{0}% Restart numbering
     \renewcommand{\item}{% Update \item to check whether enumi is odd (for 'a'/'b' suffic
       \ifodd\value{enumi}\else\stepcounter{pairitem}\fi
       \olditem
     }}
  {\end{enumerate}}

\begin{document}

\begin{pairenumerate}
  \item item 1a
  \item item 1b

  \item\label{foo} item 2a
  \item item 2b
\end{pairenumerate}

Item~\ref{foo} is nice.

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .