
패키지 를 사용하여 알고리즘에 대한 간단한 사용자 정의 환경을 사용하는 문서가 있습니다 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
뒤에 있을 수도 있음). 0으로 설정하고 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
고무공간(늘어나는 공간)이다. 나는 당신이 고정된 길이를 선호할 것이라고 생각합니다.