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.

How can I avoid the line break at the begin of an enumerate environment? I've noticed that theorem-style environments succeed in doing so. I'm using the enumitem package and my concrete example is:

\textbf{Example:} % don't want a line break here!
\begin{enumerate}
  \item test1
  \item test2
\end{enumerate}

I tried wrapping the enumerate in a vbox but that just shifted the entire list up...

share|improve this question
    
What behavior do you want? You want Example: 1. test 1 and then on the next line 2. test2? Should the 1 and 2 be aligned? –  TH. May 1 '11 at 19:37
    
@TH No, I only want to influence the first line. The rest of the list should be formated as usual. –  Jonathan May 1 '11 at 19:55
add comment

2 Answers

up vote 9 down vote accepted

Here's an attempt to imitate the theorem environments from the AMS classes:

\documentclass{article}

%\makeatletter
\newenvironment{myexample}
{\trivlist \item[\hskip\labelsep\textbf{Example:}]}
%  {\trivlist \item[]\setbox\@labels\hbox{\textbf{Example: }}}
  {\endtrivlist}
%\makeatother

\begin{document}
\thispagestyle{empty}

Here's some text. Here's some text. Here's some text. Here's some
text. Here's some text. Here's some text. Here's some text. Here's
some text. Here's some text. Here's some text. Here's some
text. Here's some text. Here's some text. Here's some text.
\begin{myexample}
  \begin{enumerate}
  \item Test 1
  \item Test 2
  \end{enumerate}
\end{myexample}
Here's some text. Here's some text. Here's some text. Here's some
text. Here's some text. Here's some text. Here's some text. Here's
some text. Here's some text. Here's some text. Here's some
text. Here's some text. Here's some text. Here's some text.

\end{document}

enter image description here

share|improve this answer
    
What's the purpose of the \@labels box trick here? Without an \everypar mechanism as in amsthm, it is equivalent to \item[\hskip\labelsep\textbf{Example:}]. –  Philippe Goutet May 2 '11 at 12:44
    
@Philippe Goutet: Yes, they seem equivalent; I was just being lazy and copying the mechanism used by list environments (which includes theorem environments). This really does use \everypar, since that's how the box \@labels is put onto the page. list environments accumulate the labels from nested list environments into \@labels, and \everypar dumps that onto the page. –  Phil Hirschhorn May 2 '11 at 17:19
    
precisely. As \item takes care of stacking automatically, just as well use it. What I meant about amsthm is that goes further with \everypar trickery: when the theorem is not followed by a list, it unboxes the label in order to allow long theorem titles without going into the margin (as they would with a simple \item[...]). –  Philippe Goutet May 2 '11 at 22:11
    
@Jonathan, @Philippe Gautet: I just edited the answer to use the line suggested by Philippe; it's better that way. –  Phil Hirschhorn May 3 '11 at 0:17
add comment

You can fool the first item label to typeset whatever you want. Something like this:

\documentclass{article}

\newcommand*\fixitem[1]{\item[]
  \refstepcounter{enumi}\hskip-\labelwidth\hskip-\labelsep
  #1 \labelenumi}

\begin{document}

\noindent\textbf{Example:} don't want a line break here, see below!

\begin{enumerate}
  \fixitem{\textbf{Example:}} test1
  \item test2
\end{enumerate}

\end{document}

The outcome is:

result of TeX run

share|improve this answer
add comment

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.