[Tex/LaTex] Add second enumeration item on the same line

formattinglists

I'm writing a document that has a large number of lists containing short enumeration items, and I'd like to be able to [manually] put multiple items on one line. Thus, for example, I'd like to say

  \begin{enumerate}
    \item Goes on first line.
    \samelineitem Also goes on first line.
    \item Goes on second line.
  \end{enumerate}

I'm quite happy with making the one line/two lines decision myself (in fact, I'd prefer it), so all I'm looking for is a macro that will determine the current enum counter, do the right thing regarding horizontal spacing, and print the item. It would be nice if this would work with enumerate, description, and itemize lists (or with general lists). (For a description list, I guess something like \samelineitem[newlabel] Text of item).

Is there a package with such a capability, or would anyone out there like to tell me how to do it? Thanks.

Best Answer

Here's a general solution using the enumitem package. What you want produces some strange looking lists, so I'm not sure I would recommend using it. It works for all three types of lists. The enumitem package also implements inline lists for all of the three list types. I've added an example here to show that too.

For enumerate and itemize lists, any label argument is ignored and therefore you should not use an arbitrarily specified label with those sorts of list.

\documentclass{article}
\usepackage[inline]{enumitem}   
\makeatletter
% This command ignores the optional argument for itemize and enumerate lists
\newcommand{\inlineitem}[1][]{%
\ifnum\enit@type=\tw@
    {\descriptionlabel{#1}}
  \hspace{\labelsep}%
\else
  \ifnum\enit@type=\z@
       \refstepcounter{\@listctr}\fi
    \quad\@itemlabel\hspace{\labelsep}%
\fi}
\makeatother
\parindent=0pt
\begin{document}

% Pure inline list
This is an inline list.
\bigskip 

\begin{enumerate*}
    \item First item.
    \item Second item.
    \item Third item.
    \item Fourth item.
\end{enumerate*}

\bigskip

% Combined inline list
This is a combined inline enumerated list.
\begin{enumerate}
    \item First item \inlineitem Second item\inlineitem Third item.
    \item Fourth item
    \item Fifth item
\end{enumerate}

\bigskip

% Works with itemize
This is a combined inline itemized list.
\begin{itemize}
    \item First item \inlineitem Second item \inlineitem Third item. 
    \item Fourth item
    \item Fifth item
\end{itemize}

\bigskip
% Works with description lists
This is a combined inline description list.
\begin{description}
    \item[Foo] First item \inlineitem[Bar]Second item\inlineitem[FooBar] Third item.
    \item[Bar] Fourth item
    \item[Foo] Fifth item
\end{description}

\bigskip
% Showing that it can be embedded and works with modified labels
The new command works with arbitrary labels and embedding.
\begin{enumerate}
    \item
    \begin{enumerate}[label=\Alph*.]
        \item First item\inlineitem Second item \inlineitem Third item. 
        \item Fourth item
        \item Fifth item
    \end{enumerate}
\end{enumerate}
\end{document}

output of code

Related Question