5

Consider the MWE:

\documentclass{report}
\usepackage[inline]{enumitem}
\newcommand{\foo}{Very long text to fill some lines}
\usepackage{xcolor}
\begin{document}

\begin{enumerate*}
\item \foo\ \foo
\item \foo\ \foo\ \foo
\item \foo
\end{enumerate*}

\bigskip

\textbf{\textcolor{red}{1.}} \textit{\foo\ \foo}\
\textbf{\textcolor{blue}{2.}} \foo\ \foo\ \foo\ 
\textbf{\textcolor{red}{1.}} \textit{\foo}

\end{document}

enter image description here

The first paragraph shows an inline list produced with enumitem package. It is nice!

But I'd like an easy way to obtain the result as shown in the second paragraph.

That is, I'd like the counter mod 2 and also an easy way to format the labels and item contents according to the parity.

Any idea?

3

You can define your own inline enumerate* environment:

enter image description here

\documentclass{article}

\newcommand{\foo}{Very long text to fill some lines}

\newenvironment{enumerate*}
  {\setcounter{enumi}{0}% Restart the list item counter
   \renewcommand{\item}{% Update \item to ...
     \ifvmode\else\unskip\hspace{.5em}\fi% ... insert space before label
     \refstepcounter{enumi}% ... step the enumi counter
     \ifodd\value{enumi}
       \normalfont\textcolor{red}{\textbf{\theenumi.}}\itshape
     \else% \value{enumi} is even
       \normalfont\textcolor{blue}{\textbf{\theenumi.}}%
       \setcounter{enumi}{0}% Reset counter
     \fi
     \hspace{.5em}% Space after item label
     \nobreak% Avoid breaks after setting the label + space
   }
  }{}

\usepackage{xcolor}
\begin{document}

\begin{enumerate*}
  \item \foo\ \foo
  \item \foo\ \foo\ \foo
  \item \foo
\end{enumerate*}

\bigskip

\textbf{\textcolor{red}{1.}} \textit{\foo\ \foo}\
\textbf{\textcolor{blue}{2.}} \foo\ \foo\ \foo\ 
\textbf{\textcolor{red}{1.}} \textit{\foo}

\end{document}
| improve this answer | |
6

You can try the following and adjust to your needs:

\documentclass{report}
\usepackage[inline]{enumitem}
\newcommand{\foo}{Very long text to fill some lines}
\usepackage{xcolor}

\newcommand*{\modtwolabel}[1]{\ifodd#1%
                           \textbf{\textcolor{red}{1.}}%
                         \else 
                           \textbf{\textcolor{blue}{2.}}%
                         \fi}

\begin{document}

\begin{enumerate*}[label={\protect\modtwolabel{\value*}}]
\item \foo\ \foo
\item \foo\ \foo\ \foo
\item \foo
\end{enumerate*}

\bigskip

\textbf{\textcolor{red}{1.}} \textit{\foo\ \foo}\
\textbf{\textcolor{blue}{2.}} \foo\ \foo\ \foo\ 
\textbf{\textcolor{red}{1.}} \textit{\foo}

\end{document}

inline enumerate mod two

With a bit of extra markup this will also influence the item contents. In passing I learned of enumitem's \AddEnumerateCounter which promised a cleaner interface to my \modtwolabel, but couldn't get it to work.

\documentclass{report}
\usepackage[inline]{enumitem}
\newcommand{\foo}{Very long text to fill some lines}
\usepackage{xcolor}

\newif\ifoddlabel
\newcommand*{\modtwolabel}[1]{\ifodd#1%
                           \textbf{\textcolor{red}{1.}}%
                           \global\oddlabeltrue
                         \else 
                           \textbf{\textcolor{blue}{2.}}%
                           \global\oddlabelfalse
                         \fi}

\newcommand*{\sigur}{\relax\ifoddlabel\itshape\fi}


\begin{document}

\begin{enumerate*}[label={\protect\modtwolabel{\value*}}]
\item\sigur \foo\ \foo
\item\sigur \foo\ \foo\ \foo
\item\sigur \foo
\end{enumerate*}

\bigskip

\textbf{\textcolor{red}{1.}} \textit{\foo\ \foo}\
\textbf{\textcolor{blue}{2.}} \foo\ \foo\ \foo\ 
\textbf{\textcolor{red}{1.}} \textit{\foo}

\end{document}

inline enumerate with mod two contents two

| improve this answer | |
  • Good. So the label problem was solved. Remains the item contents. Thanks. – Sigur Jan 1 '15 at 20:57
  • Where are you using the command \sigur? – Sigur Jan 1 '15 at 21:48
  • \sigur is an extra mark-up after \item, it checks a flag which was set from inside the label. egreg's answer avoids that with a bunch of \aftergroup's to strategically insert a \itshape. In my proposal, you do the insertion yourself but in a way allowing you later on toc permute items, the oddness of the label is computed automatically. – user4686 Jan 1 '15 at 21:50
  • I asked since I didn't see it being used anywhere. Defined but not used. – Sigur Jan 1 '15 at 21:52
  • it is used in the second code sample... – user4686 Jan 1 '15 at 21:53
5

It's not really clear why you'd want to do it, but here it is.

\documentclass{report}
\usepackage[inline]{enumitem}
\usepackage{etoolbox}
\usepackage{xcolor}

\newcommand\agi{\aftergroup\aftergroup\aftergroup\itshape}
\newcommand\agu{\aftergroup\aftergroup\aftergroup\upshape}

\newrobustcmd{\SP}{}
\newrobustcmd{\modulotwo}[4]{%
  % #1 = color for odd, #2 = color for even, #3 = format, #4 = counter
  \upshape
  \ifodd#4\relax
    \def\SP{1}\textcolor{#1}{#3}\aftergroup\agi
  \else
    \def\SP{2}\textcolor{#2}{#3}\aftergroup\agu
  \fi
}

\newcommand{\foo}{Very long text to fill some lines}
\begin{document}

\begin{enumerate*}[label=\modulotwo{red}{blue}{\SP.}{\value*}]
\item \foo\ \foo
\item \foo\ \foo\ \foo
\item \foo
\end{enumerate*}

\bigskip

\begin{enumerate*}[label=\modulotwo{red}{blue}{(\SP)}{\value*}]
\item \foo\ \foo
\item \foo\ \foo\ \foo
\item \foo
\end{enumerate*}

\end{document}

enter image description here

In the third argument to \modulotwo you specify the formatting; the number (1 or 2) is represented by \SP.


A different implementation without enumerate that doesn't really seem what you need.

\documentclass{report}
\usepackage{xcolor}

\newenvironment{twovoices}
 {\setcounter{twovoices}{0}%
  \trivlist\item\relax\hspace{\parindent}\hspace{-\voiceindent}%
  \let\item\twovoicesitem}
 {\endtrivlist}
\newcommand{\twovoicesitem}{%
  \stepcounter{twovoices}%
  \upshape\hspace{\voiceindent}%
  \ifodd\value{twovoices}%
    \textcolor{red}{1.}\itshape
  \else
    \textcolor{blue}{2.}%
  \fi
  \nolinebreak\enspace\ignorespaces
}
\newcounter{twovoices}
\newlength{\voiceindent}
\setlength{\voiceindent}{2em plus .5em minus .5em}

\newcommand{\foo}{Very long text to fill some lines}
\begin{document}

\begin{twovoices}
\item \foo\ \foo
\item \foo\ \foo\ \foo
\item \foo
\end{twovoices}

\end{document}

enter image description here

| improve this answer | |
  • It will be used to split a long paragraph to be read by 2 people. I'll read your code. – Sigur Jan 1 '15 at 21:21
  • I liked the second solution. It is simpler and easy to control spaces around items. Thanks. – Sigur Jan 1 '15 at 21:45

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.