我有以下算法,我希望“if”为“IF”。参见代码:
\documentclass{article}
\usepackage[linesnumbered,ruled,vlined]{algorithm2e}
\RestyleAlgo{boxruled}
\begin{document}
\begin{algorithm}[H]
\SetAlgoLined
\textbf{Input} : A graph $G$\;
\textbf{Find} : Graph and its color\\
\uIf{Complement o}{
Do nothng \\~\\
}
Do different things here
\caption{ \textsc{ Algorithm Graph }}
\label{algo8}
\end{algorithm}
\end{document}
问题 :如何在下面给出的算法中将“if”更改为“IF”?
答案1
以下示例修复了许多问题:
无需明确说明
\caption
即可使用的通用格式;\scshape
对和使用关键字
\Input
格式\Find
;if
重新定义使用大写字母设置条款的方式;以及一致使用
\;
行尾字符。
\documentclass{article}
\usepackage[linesnumbered,ruled,vlined]{algorithm2e}
\usepackage{etoolbox}
\AtBeginEnvironment{algorithm}{%
\let\oldcaption\caption
\renewcommand{\caption}[2][]{%
% https://tex.stackexchange.com/q/53068/5764
\if\relax\detokenize{##1}\relax
\oldcaption[#2]{\scshape #2}%
\else
\oldcaption[#1]{\scshape #2}%
\fi
}%
}
\DontPrintSemicolon
\RestyleAlgo{boxruled}
\SetKwInOut{Input}{Input}
\SetKwInOut{Find}{Find}
\SetKwIF{If}{ElseIf}{Else}{IF}{THEN}{ELSEIF}{ELSE}{ENDIF}
\begin{document}
\begin{algorithm}[H]
\caption{Algorithm graph}
\Input{A graph $G$}
\Find{Graph and its color}
\uIf{Complement o}{
Do nothing \;
Do something \;
}
Do different things here\;
\end{algorithm}
\end{document}