我有一个文档,它使用一个简单的自定义算法环境,使用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
都是一个橡胶空间(可拉伸的空间)。我想你会更喜欢固定长度。