Is there a way to change the vertical space before/after theorem environments, without defining a new theorem style? I'm using amsthm
package to define my new theorem environments.
[Tex/LaTex] How to change space around theorem environments
amsthmspacing
Related Solutions
I suggest you define a new environment for the first level enumerations in theorems, the only one that must be treated specially:
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[american]{babel}
\usepackage{enumitem}
\usepackage{amsthm}
\newtheoremstyle{mythmstyle}%
{0.5em}% space above
{0.5em}% space below
{}% body font
{}% indent amount
{\sffamily\bfseries}% head font
{}% punctuation after head
{\newline}% space after head
{\thmname{#1}\ \thmnumber{#2}\ \thmnote{(#3)}}% head spec
\theoremstyle{mythmstyle}
\newtheorem{theorem}{Theorem}
% list settings
\setlist{% general list settings (enumitem's itemize, enumerate, and description)
align=left,% left-aligned enumerate
labelsep=*,% align all item bodies vertically
leftmargin=*,% no left indent
topsep=0mm,% space before enumerate
itemsep=0mm% space between enumerate items
}
\setlist[enumerate,1]{label=\alph*)}% enumerate label on level 1
\setlist[enumerate,2]{label=\roman*)}% enumerate label on level 2
% vertical spacing after theorem heads (suggested by David Carlisle)
\makeatletter
\newenvironment{tenumerate}[1][]
{\if@inlabel
\noindent\par\nobreak\vskip-\parskip\vskip-\baselineskip\hrule\@height\z@
\fi
\enumerate[topsep=3pt,#1]}
{\endenumerate}
\makeatother
\begin{document}
\begin{theorem}% perfectly fine with David's solution: no vertical space
\begin{tenumerate}
\item Foo
\item Bar
\end{tenumerate}
\end{theorem}
\bigskip
\begin{enumerate}
\item Foobar
\item \begin{enumerate}
\item Foo
\item Bar
\end{enumerate}
\end{enumerate}
\end{document}
New way
It seems that a different strategy can work without a new environment:
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[american]{babel}
\usepackage{enumitem}
\usepackage{amsthm}
\usepackage{etoolbox}
\newif\ifstarttheorem
\newtheoremstyle{mythmstyle}%
{0.5em}% space above
{0.5em}% space below
{}% body font
{}% indent amount
{\sffamily\bfseries\global\starttheoremtrue}% head font
{}% punctuation after head
{\newline}% space after head
{\thmname{#1}\ \thmnumber{#2}\ \thmnote{(#3)}}% head spec
\theoremstyle{mythmstyle}
\newtheorem{theorem}{Theorem}
% list settings
\setlist{% general list settings (enumitem's itemize, enumerate, and description)
align=left,% left-aligned enumerate
labelsep=*,% align all item bodies vertically
leftmargin=*,% no left indent
topsep=0mm,% space before enumerate
itemsep=0mm% space between enumerate items
}
\setlist[enumerate,1]{label=\alph*)}% enumerate label on level 1
\setlist[enumerate,2]{label=\roman*)}% enumerate label on level 2
% vertical spacing after theorem heads (suggested by David Carlisle)
\makeatletter
\preto\enumerate{%
\if@inlabel
\ifstarttheorem
\mbox{}\par\nobreak\vskip\glueexpr-\parskip-\baselineskip+3pt\relax\hrule\@height\z@
\global\starttheoremfalse
\fi
\fi}
\preto\endenumerate{\global\starttheoremfalse}
\makeatother
\begin{document}
This is not a theorem.
\begin{enumerate}
\item Foo
\item Bar
\end{enumerate}
\begin{theorem}
This is a theorem.
\begin{enumerate}
\item Foo
\item Bar
\end{enumerate}
\end{theorem}
This is not a theorem.
\begin{enumerate}
\item Foo
\item Bar
\end{enumerate}
\begin{theorem}
\begin{enumerate}
\item Foo
\item Bar
\end{enumerate}
\end{theorem}
\begin{theorem}
\begin{enumerate}
\item Foobar
\item \begin{enumerate}
\item Foo
\item Bar
\end{enumerate}
\end{enumerate}
\end{theorem}
\bigskip
\end{document}
Every theorem environment sets a conditional to true; if this conditional is true, an enumerate
environment receives David's special treatment and sets the conditional to false. In order not to get false positives, also enumerate
sets the conditional to false when it ends.
Yes, you missed that you can pass options to the environment; in particular you can use skipabove=<length>
, skipbelow=<length>
:
\newmdtheoremenv[skipabove=\topsep,skipbelow=\topsep]{assum}{Assumption}[chapter]
Your example:
\documentclass{book}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{mdframed}
\theoremstyle{definition}
\newmdtheoremenv[skipabove=\topsep,skipbelow=\topsep]{assum}{Assumption}[chapter]
\begin{document}
\chapter{Fluid mechanics}
\section{Fields}
The following fields are of particular interest:
\begin{itemize}
\item $\rho$: fluid density (time-dependent scalar field);
\item $p_{\text{tot}}$: total pressure in the fluid (time-dependent scalar field);
\item $v$: velocity of the fluid parcels (time-dependent vector field).
\end{itemize}
\begin{assum}[Differentiability of tensor fields]
\label{assum:differentiability}
All tensor fields of interest are differentiable (weakly, at least).
\end{assum}
Assumption~\ref{assum:differentiability} blah blah
\subsubsection{Mass-continuity equation}
The mass-continuity equation is derived from the principle of conservation of mass:
\begin{assum}[Conservation of mass]
\label{assum:conservation_of_mass}
Fluid density $\rho$ is a conserved quantity within fluid parcels: if $V_{\text{fp}}(t)$ delimits a region of space occupied by a fluid parcel at time $t$, then
\begin{equation}
\frac{\mathrm{d}\phantom{t}}{\mathrm{d}t} \iiint_{ V_{\text{fp}}(t)} \rho \, \mathrm{d}V = 0\,.
\end{equation}
\end{assum}
blablah
\end{document}
This answers your two first questions; regarding the third one, if your frames must allow page breaks, the possibilities are basically mdframed
or framed
; this question compares them: framed or mdframed? (Pros/Cons).
Related Question
- [Tex/LaTex] Wrong vertical space in theorem environment closed by an equation
- [Tex/LaTex] Adding vertical space (\vspace) around custom environment
- [Tex/LaTex] No indentation after theorem environment with amsthm
- [Tex/LaTex] How change vertical space after head in theorem-like environment
- [Tex/LaTex] No space before or after the theorem environment
Best Answer
Without defining new theorem styles, you can modify the macro that's used by default, which is
\thm@space@setup
The default value is
\topsep
. You don't need to have the same space above and below the theorem.