¿Cómo posicionar el entorno mdframed en la parte superior de una página, sin que se disminuyan los márgenes superiores?

¿Cómo posicionar el entorno mdframed en la parte superior de una página, sin que se disminuyan los márgenes superiores?

Tengo un documento que utiliza un entorno personalizado simple para algoritmos, usando el mdramedpaquete.

Algunas veces quiero que un algoritmo se coloque en su posición en el texto y otras veces me gustaría que se coloque un algoritmo en la parte superior de su página. En el último caso, lo he logrado simplemente envolviendo el entorno del algoritmo en una figura y luego estableciendo la posición de la figura en [t!].

Sin embargo, el espacio entre la parte superior del cuadro mdframed y el texto del cuadro parece disminuir cuando se colocan en la parte superior de una página como esta.

Mi pregunta:¿Cómo puedo colocar algunos de mis entornos de algoritmo en la parte superior de las páginas, sin que la posición cambie el espacio de los márgenes entre el cuadro del algoritmo y el texto dentro del cuadro del algoritmo?

Aquí hay un pequeño ejemplo que resalta el problema:

\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}

Respuesta1

Hay una interacción entre el mdframedy el estilo algstyle: los espacios debajo y encima del teorema no se muestran correctamente (no sé por qué, tal vez algunos \addvspacedetrás). Sugiero ponerlos a cero y gestionar el espaciado con mdframed(teclas innertopmarginy innerbottommargin).

Ejemplo:

\newenvironment{ourbox}{%
  \begin{mdframed}[%
      hidealllines=false,
      innerleftmargin=10pt,
      backgroundcolor=white!10,
      innertopmargin=5pt,
      innerbottommargin=5pt,
      roundcorner=10pt]%
  }{\end{mdframed}}

\newtheoremstyle{algstyle}% name of the style to be used
  {0pt}% measure of space to leave above the theorem. E.g.: 3pt
  {0pt}% 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)}}}

En fin, \topsepes un espacio de goma (un espacio que se estira). Creo que preferirás una longitud fija.

información relacionada