No indentation after theorem environment while avoiding additional vertical space between two theorems [duplicate]

As already asked here (No indentation after theorem environment with amsthm), I would like to avoid the indentation after a theorem.

\AfterEndEnvironment{thm}{\noindent\ignorespaces}


to the theorem definition.

While this solution does work for me, it introduces new, undesired vertical space between two theoreoms when they are not separated by some text paragraph.

MWE:

\documentclass{scrbook}

\usepackage{amsthm}

\theoremstyle{plain}
\newtheorem{thm}{Theorem}[chapter]
\newtheorem*{thm*}{Theorem}

\usepackage{etoolbox}
\AfterEndEnvironment{thm}{\noindent\ignorespaces}

\begin{document}

\chapter{Chapter}

\section{Section}

Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text.

\begin{thm}
Theorem. Theorem. Theorem. Theorem. Theorem. Theorem. Theorem. Theorem. Theorem. Theorem.
\end{thm}

Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text.

\begin{thm}
Theorem. Theorem. Theorem. Theorem. Theorem. Theorem. Theorem. Theorem. Theorem. Theorem.
\end{thm}

\begin{thm}
Theorem. Theorem. Theorem. Theorem. Theorem. Theorem. Theorem. Theorem. Theorem. Theorem.
\end{thm}

Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text.

\end{document}


marked as duplicate by egreg, Bobyandbob, Troy, Community♦Dec 5 '17 at 11:16

• The accepted answer is unfortunately wrong. I added a better solution. – egreg Dec 5 '17 at 10:45

\noindent starts a new paragraph. This is imho the wrong way to suppress the identation. I would either use like lists \@doendpe, which suppress the identation only if there is no empty line after the environment, or like \section \setbox\z@\lastbox at the next par.

\documentclass{scrbook}

\usepackage{amsthm}

\theoremstyle{plain}
\newtheorem{thm}{Theorem}[chapter]
\newtheorem*{thm*}{Theorem}

\usepackage{etoolbox}
\makeatletter
%\AfterEndEnvironment{thm}{\@doendpe}
\AfterEndEnvironment{thm}{\everypar{\setbox\z@\lastbox\everypar{}}}
\makeatother

\begin{document}

\chapter{Chapter}

\section{Section}

Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text.

\begin{thm}
Theorem. Theorem. Theorem. Theorem. Theorem. Theorem. Theorem. Theorem. Theorem. Theorem.
\end{thm}
Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text.

Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text.

\begin{thm}
Theorem. Theorem. Theorem. Theorem. Theorem. Theorem. Theorem. Theorem. Theorem. Theorem.
\end{thm}

\begin{thm}
Theorem. Theorem. Theorem. Theorem. Theorem. Theorem. Theorem. Theorem. Theorem. Theorem.
\end{thm}

Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text.

\end{document}

• Thank you for the answer, I really like the 'lazy option' which always removes the indentation, regardless of the existence of an empty line. – jpmath Dec 5 '17 at 11:15