Control space between paragraph and example environment - amsthm package

Which parameter sets the spacing before and after of the example environment from amsthm library?

MWE:

\documentclass{article}
\usepackage{lipsum}
\usepackage{amsthm}

\newtheorem{example}{Exam}[section]

\begin{document}

\section{My section}
\lipsum[2] % Dummy text
\begin{example}
\lipsum[1] % Dummy text
$$x^2 + y^2 = 1$$
\end{example}
\lipsum[2] % Dummy text

\end{document}

• amsthm has three different theorem styles, one of which -- remark -- has no extra space above and below. it would probably be a good idea to investigate this before trying to change the predefined spacing. – barbara beeton Dec 18 '12 at 16:48

The amsthm package offers three predefined styles for the theorem-like structures: plain (the default style), definition and remark; the remark style leaves less space before and after the structure than the other two styles, as can be seen in the following example:

\documentclass{article}
\usepackage{amsthm}
\usepackage[hmargin=2cm]{geometry}% just for the example
\usepackage{lipsum}% just to generate text for the example

\newtheorem{exai}{Plain}
\theoremstyle{definition}
\newtheorem{exaii}{Definition}
\theoremstyle{remark}
\newtheorem{exaiii}{Remark}

\begin{document}

\lipsum[4]
\begin{exai}
\lipsum[4]
\end{exai}
\lipsum[4]
\begin{exaii}
\lipsum[4]
\end{exaii}
\lipsum[4]
\begin{exaiii}
\lipsum[4]
\end{exaiii}
\lipsum[4]

\end{document}


The internal lengths controlling the spacing before and after the structures are \thm@preskip (for the space before) and \thm@postskip (for the space after); in amsthm.sty one finds:

\def\thm@space@setup{%
\thm@preskip=\topsep \thm@postskip=\thm@preskip


So the value of \topsep will be used for the structures built with the plain and definition styles; on the other hand, for the remark style, amsthm.sty has:

\def\th@remark{%
\normalfont % body font
\thm@preskip\topsep \divide\thm@preskip\tw@
\thm@postskip\thm@preskip
}


so, for the remark style, half the value of \topsep will be used for the structures built with this style.

If you want to change the default value for the plain and definition styles, you could then use in the preamble something like

\makeatletter
\def\thm@space@setup{%
\thm@preskip=.5\topsep \thm@postskip=\thm@preskip
}
\makeatother


A complete example:

\documentclass{article}
\usepackage{lipsum}
\usepackage{amsthm}

\makeatletter
\def\thm@space@setup{%
\thm@preskip=.5\topsep \thm@postskip=\thm@preskip
}
\makeatother

\newtheorem{example}{Exam}[section]

\begin{document}

\section{My section}
\lipsum[2] % Dummy text
\begin{example}
\lipsum[1] % Dummy text
$$x^2 + y^2 = 1$$
\end{example}
\lipsum[2] % Dummy text

\end{document}


Of course, this will affect all theorem-like structures for the two styles plain and definition, and it will also affect the spacing after the structure, since \thm@postskip=\thm@preskip; if you want the change only for a particular structure, you can use \newtheoremstyle (refer to the documentation for amsthm) to define the settings appropriately. A little example (using a space that is too small. but it is just for example purposes):

\documentclass{article}
\usepackage{lipsum}
\usepackage{amsthm}

\newtheoremstyle{example}% ⟨name⟩
{3pt}%⟨Space above⟩
{3pt}%⟨Space below⟩
{\itshape}%⟨Body font⟩
{}%⟨Indent amount⟩
{}%⟨Theorem head spec (can be left empty, meaning ‘normal’)⟩
\theoremstyle{example}
\newtheorem{example}{Exam}[section]

\begin{document}

\section{My section}
\lipsum[2] % Dummy text
\begin{example}
\lipsum[1] % Dummy text
$$x^2 + y^2 = 1$$
\end{example}
\lipsum[2] % Dummy text

\end{document}

• When I use library \usepackage{parskip} the \thm@preskip=.5\topsep \thm@postskip=\thm@preskip doesn't work. – JardaFait Dec 19 '12 at 11:41
• @jafan I did some tests and it still works when the parskip package is loaded; if it doesn't for you, you should consider opening a new question with this new issue. – Gonzalo Medina Dec 19 '12 at 14:43