是否可以自定义algorithm2e
浮点数的装箱规则宽度和颜色?
\documentclass{article}
\usepackage{algorithm2e}
\begin{document}
% \RestyleAlgo{boxed}
\RestyleAlgo{boxruled}
\LinesNumbered
\begin{algorithm}[ht]
\caption{My algorithm\label{alg}}
Statement
\end{algorithm}
\end{document}
答案1
我不确定这是否会意外地破坏其他东西......
\documentclass{article}
\usepackage{xcolor,regexpatch}
\usepackage[linesnumbered]{algorithm2e}
\begin{document}
\begin{algorithm}
\caption{My algorithm}
Statement
\end{algorithm}
\makeatletter
\newlength{\algorithmboxrule}
\setlength{\algorithmboxrule}{2pt}
\newcommand{\algorithmboxcolor}{orange}
\xpatchcmd*{\algocf@caption@boxruled}{0.8pt}{2\algorithmboxrule}{}{}
\xpatchcmd*{\algocf@caption@boxruled}{\vrule}{\vrule width \algorithmboxrule}{}{}
\xpatchcmd{\algocf@caption@boxruled}{\hrule}{\hrule height \algorithmboxrule}{}{}
\xpretocmd{\algocf@caption@boxruled}{\color{\algorithmboxcolor}}{}{}
\setlength{\fboxsep}{\dimexpr\fboxsep+\fboxrule-\algorithmboxrule}
\setlength{\fboxrule}{\algorithmboxrule}
\makeatother
\RestyleAlgo{boxruled}
\begin{algorithm}
\caption{My algorithm}
Statement
\end{algorithm}
\makeatletter
\xpatchcmd{\@algocf@post@boxed}{\framebox}{\color{\algorithmboxcolor}\framebox}{}{}
\makeatother
\RestyleAlgo{boxed}
\begin{algorithm}
\caption{My algorithm}
Statement
\end{algorithm}
\end{document}
请注意,算法框是使用\fbox
(或\framebox
)设置的。因此,在必要时对\fboxsep
和/或\fboxrule
进行了调整。但是,这可能会影响您使用 的其他位置\fbox
。