[Tex/LaTex] How to remove line breaks before and after theorems

line-breakingspacingtheorems

By default, in the amsthm package, when you begin a theorem, LaTeX begins on a new line, and when you end the theorem, it also jumps to a new line. How can you prevent this behavior?

For example, I might want to display something like this.

Example text before theorem. \begin{thm}This is a theorem.\end{thm} Example text after theorem.

In this example, I would like the example text before and after to appear inline with the theorem.

Best Answer

You could define your own shortthm environment:

enter image description here

\documentclass{article}
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\usepackage{amsthm}% http://ctan.org/pkg/amsthm
\newtheorem{thm}{Theorem}
\makeatletter
\newenvironment{shortthm}
  {\enskip\refstepcounter{thm}\textbf{Theorem~\thethm.\space}\itshape}% \begin{shortthm}
  {\enskip}% \end{shortthm}
\makeatother
\begin{document}
\lipsum[1]
\begin{thm}
This is a theorem
\end{thm}
\lipsum[2]
Example text before theorem. \begin{shortthm}This is a theorem.\end{shortthm} Example text after theorem.
\end{document}​

Note that this usage might be confusing to readings, since there is no clear distinction between the theorem body and body text - provided by default when using the line break of amsthm.

The above shortthm is very crude, but could be extended to form part of the creation when issuing \newtheorem{<theorem>}{<title>}. Also, it could also be made a macro, but I kept it in an environment form. The preceding and following text is separated by \enskip; assuming of course that you're not starting a paragraph with it. However, that can also be modified.