
현재 다음 mwe를 사용하고 있습니다
\documentclass{article}
\usepackage{algpseudocode}
\usepackage[plain]{algorithm}
\begin{document}
\begin{algorithm}[H]
\hrule
\vspace{0.5em}
\caption{Euclide's algorithm}\label{euclid}
\begin{algorithmic}[5]
\Procedure{Euclide}{$a,b$}\Comment{The g.c.d. of a and b}
\State $r\gets a\bmod b$
\While{$r\not=0$}\Comment{We have the answer if r is 0}
\State $a\gets b$
\State $b\gets r$
\State $r\gets a\bmod b$
\EndWhile\label{euclidendwhile}
\State \Return $b$\Comment{The gcd is b}
\EndProcedure
\end{algorithmic}
\hrule
\end{algorithm}
\end{document}
일반 스타일과 괘선 스타일을 혼합하여 얻으려면( 참고 hrule
). 나는 그것이 유도하는 텍스트 분리를 위한 규칙을 좋아하고, 내 문서 전반에 걸쳐 캡션 스타일을 존중하는 평범한 것을 좋아합니다. 사진을 참조하세요.
일반 환경을 재정의하는 쉬운 방법이 있습니까? 나는 대답을 사용하려고 노력했습니다이 질문
\makeatletter
\let\oldalgorithmic\algorithmic
\def\algorithmic{\@ifnextchar[\algorithmic@i \algorithmic@ii}
\def\algorithmic@i[#1]{\hrule\vspace{0.5em}\oldalgorithmic[#1]\hrule}
\def\algorithmic@ii[#1]{\hrule\vspace{0.5em}\oldalgorithmic\hrule}
\makeatother
그러나 두 번째 시간 규칙이 여전히 알고리즘의 최상위에 있기 때문에 이는 예상대로 작동하지 않습니다. 뭔가 빠졌나요?
답변1
algorithm
을 사용합니다float
패키지algorithm
s를 사용하여 환경 스타일을 지정합니다 \floatstyle
. plain
및 의 플로트 스타일은 다음과 같습니다 ruled
.
% The 'plain' float style
\newcommand\fs@plain{\def\@fs@cfont{\rmfamily}\let\@fs@capt\floatc@plain
\def\@fs@pre{}\def\@fs@post{}%
\def\@fs@mid{\vspace\abovecaptionskip\relax}%
\let\@fs@iftopcapt\iffalse}
% The 'ruled' float style
\newcommand\fs@ruled{\def\@fs@cfont{\bfseries}\let\@fs@capt\floatc@ruled
\def\@fs@pre{\hrule height.8pt depth0pt \kern2pt}%
\def\@fs@post{\kern2pt\hrule\relax}%
\def\@fs@mid{\kern2pt\hrule\kern2pt}%
\let\@fs@iftopcapt\iftrue}
각 부동 스타일은 부동을 구성하는 데 사용되는 구성 요소 수를 정의합니다. 부동 소수점 스타일을 고려하십시오 ruled
. pre
- 및 post
- 구성 요소가 를 둘러싸는 \caption
반면 mid
- 구성 요소는 부동 소수점에서 끝납니다.
plainruled
이것을 기초로 사용하여 두 가지 모두를 갖춘 새로운 float 스타일을 만들 수 있습니다 .
\documentclass{article}
\usepackage{algpseudocode,algorithm}
\makeatletter
% The 'plainruled' float style
\newcommand\fs@plainruled{\def\@fs@cfont{\rmfamily}\let\@fs@capt\floatc@plain
\def\@fs@pre{\hrule height.8pt depth0pt \kern2pt}%
\def\@fs@post{}%
\def\@fs@mid{\kern2pt\hrule height.8pt depth0pt\relax\kern\abovecaptionskip}%
\let\@fs@iftopcapt\iffalse}
\makeatother
\floatstyle{plainruled}
\restylefloat{algorithm}
\begin{document}
\begin{algorithm}[H]
\caption{Euclide's algorithm}\label{euclid}
\begin{algorithmic}[5]
\Procedure{Euclide}{$a,b$}\Comment{The g.c.d.\ of~$a$ and~$b$}
\State $r \gets a \bmod b$
\While{$r \neq 0$}\Comment{We have the answer if~$r$ is~$0$}
\State $a \gets b$
\State $b \gets r$
\State $r \gets a \bmod b$
\EndWhile\label{euclidendwhile}
\State \Return $b$\Comment{The g.c.d.\ is~$b$}
\EndProcedure
\end{algorithmic}
\end{algorithm}
\end{document}