2

I'm trying to colorize the 3 horizontal lines appearing at the top and bottom of the algorithm below. I haven't been able to find similar issues in the internet. Could you please advise?

\documentclass[11pt,a4paper]{article}
\usepackage[no-math]{fontspec}
\usepackage[dvipsnames,svgnames,table,fixpdftex]{xcolor}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage[ruled,linesnumbered]{algorithm2e}


\begin{document}        

\begin{algorithm}
\SetArgSty{textnormal}
\SetKwInOut{Input}{Input}
\SetKwInOut{Output}{Output}
\DontPrintSemicolon
\Input{A point $P$, an $n$-bit integer $k=\displaystyle\sum_{i=0}^{n-1} k_{(i)}2^i$}
\Output{$Q=[k]P$}
\Begin{
 $Q \longleftarrow \mathcal{O}$\;
 \For{$i=n-1$ to $0$}
 {
    $Q \longleftarrow [2]Q$\;
    \If{$k_{(i)}=1$}{
        $Q \longleftarrow Q+P$
    }
 }
 \Return{$Q$}
}

\caption{Binary method for EC point multiplication} \label{alg1}
\end{algorithm}

\end{document}

Result is shown below. The lines with the arrows need to get some color

1 Answer 1

3

The following setup allows you to adjust these colours to suit your needs via the provided macros:

\setalgotoprulecolor{<colour>}
\setalgomidrulecolor{<colour>}
\setalgobotrulecolor{<colour>}

enter image description here

\documentclass{article}

\usepackage[dvipsnames,svgnames,table]{xcolor}
\usepackage{amsmath,amssymb}
\usepackage[ruled,linesnumbered]{algorithm2e}

% algorithm2e settings
\SetArgSty{textnormal}
\SetKwInOut{Input}{Input}
\SetKwInOut{Output}{Output}
\DontPrintSemicolon
\newcommand{\assign}{\longleftarrow}

\makeatletter
\newcommand{\setalgotoprulecolor}[1]{\colorlet{toprulecolor}{#1}}
\let\old@algocf@pre@ruled\@algocf@pre@ruled % Adjust top rule colour
\renewcommand{\@algocf@pre@ruled}{\textcolor{toprulecolor}{\old@algocf@pre@ruled}}

\newcommand{\setalgobotrulecolor}[1]{\colorlet{bottomrulecolor}{#1}}
\let\old@algocf@post@ruled\@algocf@post@ruled % Adjust middle rule colour
\renewcommand{\@algocf@post@ruled}{\textcolor{bottomrulecolor}{\old@algocf@post@ruled}}

\newcommand{\setalgomidrulecolor}[1]{\colorlet{midrulecolor}{#1}}
\renewcommand{\algocf@caption@ruled}{%
  \box\algocf@capbox{\color{midrulecolor}\kern\interspacetitleruled\hrule
    width\algocf@ruledwidth height\algotitleheightrule depth0pt\kern\interspacealgoruled}}
\makeatother

\setalgotoprulecolor{blue!30}% Default
\setalgobotrulecolor{red!30}% Default
\setalgomidrulecolor{green!30}% Default

\begin{document}        

\begin{algorithm}
  \Input{A point $P$, an $n$-bit integer $k = \sum_{i=0}^{n-1} k_{(i)}2^i$}
  \Output{$Q = [k]P$}
  \Begin{
   $Q \assign \mathcal{O}$\;
   \For{$i = n-1$ to $0$}
   {
      $Q \assign [2]Q$\;
      \If{$k_{(i)} = 1$}{
          $Q \assign Q + P$
      }
   }
   \Return{$Q$}
  }
  \caption{Binary method for EC point multiplication}
\end{algorithm}

\end{document}

The above code is specific to the ruled style of algorithm2e.

2
  • Thank you very much it worked like a charm. Much appreciated.
    – Jimakos
    Commented Mar 10, 2016 at 20:35
  • @Jimakos: If this answered your question, consider up-voting and/or accepting it as such. See How do you accept an answer?
    – Werner
    Commented Mar 10, 2016 at 23:17

You must log in to answer this question.

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