34

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.

1

4 Answers 4

35

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

2
  • This seems like a lower-overhead solution than the one proposed in the next answer; thanks. However, it has the obvious disadvantage of requiring the \inlineitem arguments to be {}-delimited. Is there an easy way around that problem? (\item in the basic list processing clearly doesn't require this). I don't know if I'll end up using this or not in the end -- it's a choice between huge amounts of whitespace, and somewhat odd-looking packing of list elements on a line.
    – rogerl
    Apr 8, 2012 at 14:10
  • @rogerl I've removed the need for braces. (Thanks to David Carlisle for pointing out the solution in chat.)
    – Alan Munn
    Apr 8, 2012 at 14:55
12

You could also use an line list for the portion you want inline, and then start a new list with the resume feature available from the enumitem package:

enter image description here

Notes:

  • If you have more that one of these in your document, you should also add the start=1 option when you start a new list to reset the label counter.

Further Enhancements:

  • The inline version is intended for use in a paragraph where there is text preceding it, and an additional space is added at the beginning of the list. Hence, it does not align properly with the subsequent non-inline list. I have added before=\hspace{-0.6ex} which seems to make the necessary adjustment. However, there probably is a better way to do this rather than hard code a specific value. Otherwise there may be cases where this needs to be tweaked.

Code:

\documentclass{article}
\usepackage[inline]{enumitem}

\begin{document}
  \begin{enumerate*}[series=MyList, before=\hspace{-0.6ex}]
    \item Goes on first line.
    \item Also goes on first line.
  \end{enumerate*}
  \begin{enumerate}[resume=MyList]
    \item Goes on second line.
  \end{enumerate}
\end{document}
2
  • the item labels in the two lines should really line up, shouldn't they? Apr 7, 2012 at 22:00
  • @barbarabeeton: Yep, had mentioned that in the "Further Enhancements" section. Have added a tweak which appears to fix it, but don't know the official way to do so. Apr 8, 2012 at 1:14
5

I found that multicol package provides a simple solution by enclosing any of the itemize, description or enumerate environments. An example:

\usepackage{multicol}

\begin{multicols}{2}
\begin{enumerate}
    \item \( \varphi(x,t)= A \mathrm{e}^{- \alpha (x- c t) } \)
    \item \( \varphi(x,t)= A \mathrm{e}^{- 2 \alpha (x- c t) } \)
    \item \( \varphi(x,t)= A \ln \left( k (x- c t) \right) \)
    \item \( \varphi(x,t)= A \left( x- c t \right) \)
    \item \( \varphi(x,t)= A \left( x- c t \right)^n \)
    \item \( \varphi(x,t)= A \sin \left( k (x- c t) \right) \)
    \item \( \varphi(x,t)= A \sin \left( \alpha (x^2- c^2 t^2) \right) \)
    \item \( \varphi(x,t)= A \left( x+ c t \right)^{1/2} \)
\end{enumerate}
\end{multicols}

Notice that multicols is used when defining the environment.

3
  • the only working method for me.
    – Sadegh
    Feb 19, 2017 at 22:30
  • Worked for me, and it looks great! Jul 30, 2020 at 22:03
  • 2
    This solution doesn't quite do the same, the items there are listed downwards first (then from left to right)
    – Sary
    Oct 20, 2020 at 14:41
5

Use of $\bullet$ works as an in-line bullet. Example:

\begin{itemize}
  \item MacOS $\bullet$ Windows $\bullet$ Linux
\end{itemize}

The above syntax prints

• MacOS • Windows • Linux

0

You must log in to answer this question.

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