修改algorthim2e的装箱,让标题就行

修改algorthim2e的装箱,让标题就行

我知道 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}

在此处输入图片描述

相关内容