
我有一個文檔,使用該包使用簡單的自訂演算法環境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
都是一個橡膠空間(一個可以伸展的空間)。我想你會更喜歡固定長度。