![修改algorthim2e的装箱,让标题就行](https://linux22.com/image/373604/%E4%BF%AE%E6%94%B9algorthim2e%E7%9A%84%E8%A3%85%E7%AE%B1%EF%BC%8C%E8%AE%A9%E6%A0%87%E9%A2%98%E5%B0%B1%E8%A1%8C.png)
我知道 algorithm2e 包允许装箱算法,但我想要实现的是:
+-------- Algorithm blablabla --------+
| |
| Input: blabla |
| Output: blabla |
| |
| |
| 1. ... the algorithm |
| |
| |
| |
| |
| |
| |
| |
| n. end |
| |
| |
+------------------------------------------+
是否可以改变包以获得所有看起来像这样的算法环境?
非常感谢你的帮助!
答案1
您可以使用tcolorbox
:
\documentclass{article}
\usepackage[linesnumbered, commentsnumbered]{algorithm2e}
\SetKwInOut{Input}{Input}
\SetKwInOut{Output}{Output}
\usepackage[most]{tcolorbox}
\tcbset{
algotitle/.style={title={\strut
Algorithm~\thetcbcounter\ifstrempty{#1}{\ignorespaces}{:~#1}}}}
\newtcolorbox[auto counter]{algo}[1][]{%
colback=white,
colframe=black,
boxrule=1pt,
titlerule=0pt,
sharp corners,
colbacktitle=white,enhanced,
attach boxed title to top center={yshift=-10pt},
boxed title style={boxrule=-1pt},
fonttitle=\bfseries,
coltitle=black,
algotitle={},
#1
}
\begin{document}
\begin{algo}[algotitle=Blablabla, label=myalgo]
\begin{algorithm}[H]
\Input{bla in}
\Output{bla out}
the algorithm
end
\end{algorithm}
\end{algo}
The caption of Algorithm \ref{myalgo} is above.
\end{document}