[Tex/LaTex] Change Algorithm caption Label color to blue and bold italics

algorithm2ecaptionsformatting

I wanted to know how to go about changing the algorithm caption label to blue and bold italics. I have so far been able to change the caption name to blue, but I have not been able to change the algorithm caption label to bold and italicized. Here is the code that I have so far:

\documentclass{article}
\usepackage{amsmath, amsfonts, amssymb, amsthm, bm}
\usepackage{commath}
\usepackage{xcolor}
\usepackage[linesnumbered,ruled,vlined]{algorithm2e}
\newcommand\mycommfont[1]{\footnotesize\ttfamily\textcolor{blue}{#1}}
\SetCommentSty{mycommfont}
\SetAlgoCaptionSeparator{.}
\renewcommand\AlCapFnt{\textit\textbf\color{blue}}
\usepackage[font={color=mybluei,bf,it},figurename=Fig.,labelfont={it}]{caption}
\begin{document}
\begin{center}
\colorbox[gray]{0.95}{
\begin{minipage}{0.65\textwidth}
\SetAlgoLined
\SetNlSty{textbf}{}{:}
\begin{algorithm}[H]
\DontPrintSemicolon
This is line one\\
This is line two numbered\\
This should be numbered\\
This should also be numbered
\caption{Unnumbered lines}
\end{algorithm} 
\end{minipage}} 
\end{center}

\end{document} 

Best Answer

algorithm2e's \caption has the following format:

\AlCapSty{\AlCapFnt Algorithm 1:}\AlCapNameSty{\AlCapNameFnt my algorithm}

Taken from the "change log":

By default, \AlCapSty is \textbf and \AlCapFnt is nothing. \AlCapNameSty keep text as it is, and \AlCapNameFnt do nothing also. You can redefine \AlCapFnt and \AlCapNameFnt by giving macro to \Set... commands. For example, you can do \SetAlCapFnt{\large} to see Algorithm printed in \large font.

You can redefine \AlCapSty, \AlCapFnt, \AlCapNameSty and \AlCapNameFnt with the corresponding \Set... command. For the \...Sty commands, you have to give in parameter name of a macro (without \) which takes one argument. For example, \SetAlCapFnt{textbf} defines the default behaviour. If you want to do more complicated thing, you should define your own macro and give it to \SetAlCapFnt or \SetAlCapNameFnt. Here are two examples:

\newcommand{\mycapsty}[1]{\tiny #1}\SetAlCapNameSty{mycapsty}
\newcommand{\mycapsty}[1]{\textsl{\small #1}}\SetAlCapNameSty{mycapsty}

Or you can combine the two, for the last example you can also do:

\SetAlCapNameSty{textsl}\SetAlCapNameFnt{\small}

With the above information, the following provides what you're after:

\renewcommand\AlCapFnt{\itshape\bfseries\color{blue}}
\renewcommand\AlCapNameFnt{\AlCapFnt}

enter image description here

\documentclass{article}

\usepackage{xcolor}
\usepackage[linesnumbered,ruled,vlined]{algorithm2e}

% \AlCapSty{\AlCapFnt Algorithm 1:}\AlCapNameSty{\AlCapNameFnt my algorithm}
\renewcommand\AlCapFnt{\itshape\bfseries\color{blue}}
\renewcommand\AlCapNameFnt{\AlCapFnt}

\begin{document}

\begin{algorithm}
  \DontPrintSemicolon
  This is line one \;
  This is line two numbered \;
  This should be numbered \;
  This should also be numbered
  \caption{Unnumbered lines}
\end{algorithm} 

\end{document}