I have a document which uses a simple custom environment for algorithms, using the mdramed
package.
Some times I want an algorithm to be placed at its position in text, and other times I would like an algorithm to be placed at the top of its page. In the latter case, I have been achieving just by wrapping the algorithm environment in a figure, and then setting the figure position to be [t!]
.
However, the spacing between the top of the mdframed box and the text in the box appears to be decreased when they are placed at the top of a page like this.
My question: how can I position some of my algorithm environments at the top of pages, without the positioning changing the margin spacing between the algorithm box and the text within the algorithm box.
Here is a small example highlighting the problem:
\documentclass{article}
\usepackage{amsmath}
\usepackage{lipsum}
\usepackage[dvipsnames]{xcolor}
\definecolor[named]{lipicsYellow}{rgb}{0.99,0.78,0.07}
\usepackage{amsthm}
\usepackage[framemethod=TikZ]{mdframed}
\usepackage{float}
\newenvironment{ourbox}{\begin{mdframed}[hidealllines=false,innerleftmargin=10pt,backgroundcolor=white!10,innertopmargin=3pt,innerbottommargin=5pt,roundcorner=10pt]}{\end{mdframed}}
\newtheoremstyle{algstyle}% name of the style to be used
{\topsep}% measure of space to leave above the theorem. E.g.: 3pt
{\topsep}% measure of space to leave below the theorem. E.g.: 3pt
{\normalfont}% name of font to use in the body of the theorem
{0pt}% measure of space to indent
{\bfseries}% name of head font
{.}% punctuation between head and body
{5pt plus 1pt minus 1pt}% space after theorem head; " " = normal interword space
{\kern0.05em{\color{lipicsYellow}\rule{0.63em}{0.63em}}\hspace*{0.62em}\thmname{#1}\thmnumber{ #2}\textnormal{\thmnote{ (#3)}}}
\theoremstyle{algstyle}
\newtheorem{algo}{Algorithm}
\newenvironment{algorithm}{\begin{ourbox}\begin{algo}}{\end{algo}\end{ourbox}}
\theoremstyle{definition}
\begin{document}
The algorithm below has a decent amount of space from the top:
\begin{algorithm}
Something interesting!
\end{algorithm}
\lipsum[1-5]
At the top of this page, we have an algorithm that is forced to be at the top of the page (and therefore has less space from the top).
\begin{figure}[t!]
\begin{algorithm}
Something else interesting!
\end{algorithm}
\end{figure}
\end{document}