Como posicionar o ambiente mdframed no topo de uma página, sem que as margens superiores sejam diminuídas?

Como posicionar o ambiente mdframed no topo de uma página, sem que as margens superiores sejam diminuídas?

Eu tenho um documento que usa um ambiente personalizado simples para algoritmos, usando o mdramedpacote.

Algumas vezes quero que um algoritmo seja colocado em sua posição no texto, e outras vezes gostaria que um algoritmo fosse colocado no topo da página. Neste último caso, consegui apenas envolver o ambiente do algoritmo em uma figura e, em seguida, definir a posição da figura como [t!].

No entanto, o espaçamento entre o topo da caixa mdframed e o texto na caixa parece diminuir quando eles são colocados no topo de uma página como esta.

Minha pergunta:como posso posicionar alguns dos meus ambientes de algoritmo no topo das páginas, sem que o posicionamento altere o espaçamento da margem entre a caixa do algoritmo e o texto dentro da caixa do algoritmo.

Aqui está um pequeno exemplo destacando o 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}

Responder1

Há uma interação entre o mdframede o estilo algstyle: os espaços abaixo e acima do teorema não são exibidos corretamente (não sei por que, talvez alguns \addvspaceatrás). Sugiro defini-los como zero e gerenciar o espaçamento com mdframed(teclas innertopmargine innerbottommargin).

Exemplo:

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

Enfim, \topsepé um espaço de borracha (um espaço que se estica). Acho que você preferirá um comprimento fixo.

informação relacionada