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.

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
       \begin{equation}
         x^2 + y^2 = 1
       \end{equation}
    \end{example}  
    \lipsum[2] % Dummy text  

\end{document}
share|improve this question
    
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

1 Answer 1

up vote 5 down vote accepted

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{%
  \thm@headfont{\itshape}%
  \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
       \begin{equation}
         x^2 + y^2 = 1
       \end{equation}
    \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⟩
{\bfseries}% ⟨Theorem head font⟩
{.}%⟨Punctuation after theorem head⟩
{.5em}%⟨Space after theorem head⟩2
{}%⟨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
       \begin{equation}
         x^2 + y^2 = 1
       \end{equation}
    \end{example}  
    \lipsum[2] % Dummy text  

\end{document}
share|improve this answer
    
When I use library \usepackage{parskip} the \thm@preskip=.5\topsep \thm@postskip=\thm@preskip doesn't work. –  jafan 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

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.