Как расположить окружение mdframed в верхней части страницы, не уменьшая при этом верхние поля?

Как расположить окружение mdframed в верхней части страницы, не уменьшая при этом верхние поля?

У меня есть документ, в котором используется простая пользовательская среда для алгоритмов с использованием mdramedпакета.

Иногда я хочу, чтобы алгоритм был помещен на свое место в тексте, а иногда я хочу, чтобы алгоритм был помещен в верхнюю часть страницы. В последнем случае я достигал этого, просто обернув окружение алгоритма в рисунок, а затем установив положение рисунка равным [t!].

Однако расстояние между верхом блока mdframed и текстом в блоке, по-видимому, уменьшается, если они размещены в верхней части страницы, как здесь.

Мой вопрос:как мне расположить некоторые из моих сред алгоритма в верхней части страниц, не изменяя при этом расстояние между полем алгоритма и текстом внутри поля алгоритма?

Вот небольшой пример, иллюстрирующий проблему:

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

решение1

mdframedМежду и стилем есть взаимодействие algstyle: пробелы под и над теоремой отображаются неправильно (не знаю почему, может быть, \addvspaceсзади). Предлагаю установить их на ноль и управлять пробелами с помощью mdframed(клавиш innertopmarginи innerbottommargin).

Пример:

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

В любом случае, \topsepэто резиновое пространство (пространство, которое растягивается). Я думаю, вы предпочтете фиксированную длину.

Связанный контент