Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

up vote 17 down vote accepted

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

share|improve this answer
    
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 '12 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 '12 at 14:55
    
Works great. Thanks. –  rogerl Apr 9 '12 at 0:23

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}
share|improve this answer
    
the item labels in the two lines should really line up, shouldn't they? –  barbara beeton Apr 7 '12 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. –  Peter Grill Apr 8 '12 at 1:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.