53

I'm currently writing up some solutions, and I like to rewrite the problem before answering it.

I've set exercise to be a theorem environment, and the code I'm using is

\begin{exercise} 
\begin{enumerate} 
\item Show that $R$ is symmetric iff $R^{-1}\subseteq R$.
\item Show that $R$ is transitive iff $R\circ R\subseteq R$.
\end{enumerate}
\begin{proof}
\end{proof}
\end{exercise}

However, when I build, the first item (a) appears immediately to the right of the Exercise heading, and the second item (b) appears below and indented:

alt text

I've tried using \newline and \linebreak, and even skipping a line before typing \begin{enumerate} after the \begin{exercise} command but those don't work. Is there a way to push (a) down below Exercise 3.32. so that it's lined up with (b)? Thank you.

As requested, my preamble is:

\documentclass[11pt]{article}
\input{other/packages.tex}
\input{other/theoremdef.tex}

where packages.tex is

\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{amscd}
\usepackage{url}
\usepackage[top=1.3in, bottom=1.3in, left=1.3in, right=1.3in]{geometry}

% header and footer
\pagestyle{headings}

\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{stackrel}
\usepackage{mathrsfs}
\usepackage{verbatim}
\usepackage{enumerate}
\usepackage{hyperref}
\usepackage{xy}
\input xy
\xyoption{all}

And theoremdef.tex is:

\newtheorem{exercise}{\bf Exercise}
\newcommand{\dom}{\text{dom}\ }
\newcommand{\ran}{\text{ran}\ }
\newcommand{\fld}{\text{fld}\ }
\newcommand{\op}[2]{\langle #1,#2\rangle}
\newcommand{\ot}[3]{\langle #1,#2,#3\rangle}
\newcommand{\ms}[1]{\mathscr{#1}}
0

7 Answers 7

54

Insert

\leavevmode

after the \begin{exercise}. That puts you into horizontal mode, which is where you want to be when you encounter the \begin{enumerate}.

4
  • Thanks Phil, this worked great. This may be a dumb question, but will I ever have to "return to vmode", as in undo the \leavevmode command, or does it leave later parts of the document unaffected?
    – yunone
    Jan 2, 2011 at 7:09
  • @yunone: \leavevmode works as \mbox{}, it does not affect other part of document.
    – Leo Liu
    Jan 2, 2011 at 7:19
  • This adds a lot of vertical space. I added \vspace*{-\bigskipamount}\vspace*{-\medskipamount} which removes the space again, but I'm not 100% sure that it's the right amount of space.
    – morxa
    Mar 12, 2017 at 9:48
  • @Phil Hirschhorn I think that \leavevmode does not work when for example we write \begin{definition}\leavevmode cccccc \end{definition}. What will be the solution? thanks
    – Schüler
    Apr 26, 2021 at 13:32
10

I believe this is what you are looking for:

\begin{exercise} 
\begin{enumerate} 
\item[]
\item Show that $R$ is symmetric iff $R^{-1}\subseteq R$.
\item Show that $R$ is transitive iff $R\circ R\subseteq R$.
\end{enumerate}
2
  • This solution worked for me when the \leavevmode solution suggested above created compilation errors ("Improper \prevdepth.")).
    – Ted
    Oct 5, 2020 at 14:48
  • این برایم مفید بود. متشکرم
    – Mikasa
    Sep 29, 2021 at 8:48
8

See theorem or ntheorem package. Here is an example:

\documentclass{article}
\usepackage{theorem} % or ntheorem
\theoremstyle{break}
\newtheorem{exercise}{Exercise}
\begin{document}
\begin{exercise}
\begin{enumerate}
  \item foo
  \item bar
\end{enumerate}
\end{exercise}
\end{document}

It may be a little more complex to do that using amsthm. In amsthm we can define:

\usepackage{amsthm}
\newtheoremstyle{break}{3pt}{3pt}{\itshape}{}{\bfseries}{.}{\newline}{}
\theoremstyle{break}
\newtheorem{exercise}{Exercise}

It works fine without a enumerate environment at the beginning, but will fail for your code. This is a solution:

\begin{exercise}\mbox{}
\begin{enumerate}
  \item foo
  \item bar
\end{enumerate}
\end{exercise}

It seems no elegant solution. Therefore I prefer ntheorem to modify theorem styles.

0
4

I've extracted the following from thmtools' handling of the listhack key:

\def\thmt@amsthmlistbreakhack{%
  \leavevmode
  \vspace{-\baselineskip}%
  \par
  \everypar{\setbox\z@\lastbox\everypar{}}%
}

I find that without the \vspace, the vertical space before the list is excessive. I don't remember right now why I put the \everypar stanza there, in particular, why I didn't use \noindent. I'll check that again.

2

I (sort of accidentally) discovered that simply using \item immediately after \begin{theorem} can achieve the desired effect. For example, try

\begin{theorem}[Name of Theorem]
\item This is a theorem with multiple parts.
    \begin{enumerate}
    \item stuff here.
    \item and here.
    \item and here, as well.
    \end{enumerate}
\end{theorem}

I haven't yet found an instance that this fails for. Hope this helps.

2
  • Welcome to TeX.SX! Could you elaborate on your solution and show some screen shot?
    – user31729
    Apr 16, 2015 at 23:36
  • 1
    This works nicer for me than \leavevmode - that is because leavevmode seems to cause a new paragraph (i.e., there is "too much" spacing between the theorem name and the enumeration). A blank \item line by itself looks much nicer!
    – MotiNK
    Jan 7, 2016 at 11:45
0

You can use \newline as a quick fix. As newline needs a line to break, you can give an empty one by ~.

\begin{exercise} 
~\newline
\begin{enumerate} 
\item Show that $R$ is symmetric iff $R^{-1}\subseteq R$.
\item Show that $R$ is transitive iff $R\circ R\subseteq R$.
\end{enumerate}
\begin{proof}
\end{proof}
\end{exercise}
-1

As Leo Liu suggested, I do this:

\begin{theorem}
  \mbox{}
  \begin{enumerate}
  \item foo
  \item bar
  \end{enumerate}
\end{theorem}

You must log in to answer this question.

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