
Ich habe ein Dokument, das unter Verwendung des Pakets eine einfache benutzerdefinierte Umgebung für Algorithmen verwendet mdramed
.
Manchmal möchte ich, dass ein Algorithmus an seiner Position im Text platziert wird, und manchmal möchte ich, dass ein Algorithmus oben auf der Seite platziert wird. Im letzteren Fall habe ich dies erreicht, indem ich die Algorithmusumgebung einfach in eine Abbildung eingebunden und dann die Abbildungsposition auf gesetzt habe [t!]
.
Allerdings scheint der Abstand zwischen der Oberseite des MDFramed-Felds und dem Text im Feld kleiner zu sein, wenn sie auf diese Weise oben auf einer Seite platziert werden.
Meine Frage:wie kann ich einige meiner Algorithmusumgebungen oben auf Seiten positionieren, ohne dass durch die Positionierung der Randabstand zwischen dem Algorithmusfeld und dem Text innerhalb des Algorithmusfelds geändert wird?
Hier ist ein kleines Beispiel, das das Problem verdeutlicht:
\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}
Antwort1
Es gibt eine Interaktion zwischen mdframed
und dem Stil algstyle
: die Leerzeichen unter und über dem Theorem werden nicht richtig angezeigt (ich weiß nicht warum, vielleicht einige dahinter). Ich schlage vor, sie auf Null zu setzen und den Abstand mit (den Tasten und ) \addvspace
zu verwalten .mdframed
innertopmargin
innerbottommargin
Beispiel:
\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)}}}
Es handelt sich jedenfalls \topsep
um einen Gummiraum (ein Raum, der sich ausdehnt). Ich glaube, Sie werden eine feste Länge bevorzugen.