7

I have a algorithm below, I want "if" to be "IF". See code:

\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}

enter image description here

Question : How to change "if" to "IF" in the algorithm given below?

1 Answer 1

8

The following example fixes a number of issues:

  • Generic formatting of the \caption to use \scshape without explicitly stating it;

  • Using keyword formatting for the \Input and \Find;

  • Redefining the way the if clause is set using capitalization; and

  • Using \; end-of-line characters consistently.

enter image description here

\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}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .