
パッケージを使用して、アルゴリズム用のシンプルなカスタム環境を使用するドキュメントがありますmdramed
。
アルゴリズムをテキスト内の所定の位置に配置したい場合もあれば、アルゴリズムをページの上部に配置したい場合もあります。後者の場合は、アルゴリズム環境を図で囲み、図の位置を に設定するだけで実現しています[t!]
。
ただし、このようにページの上部に配置すると、mdframe ボックスの上部とボックス内のテキスト間の間隔が狭くなるように見えます。
私の質問:アルゴリズム ボックスとアルゴリズム ボックス内のテキスト間の余白間隔を変更せずに、アルゴリズム環境の一部をページの上部に配置するにはどうすればよいでしょうか。
以下に、問題を強調する小さな例を示します。
\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
。定理の下と上のスペースが正しく表示されません (理由はわかりませんが、後ろに何かあるのかもしれません)。それらを 0 に設定し、 (キーと)\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
ゴムスペース(伸びるスペース)です。固定長の方がいいと思います。