Text Formattingalgorithms | Colored horizontal Lines for Algorithms

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
carlosborrego
Posts: 6
Joined: Sun Dec 09, 2012 1:45 pm

algorithms | Colored horizontal Lines for Algorithms

Post by carlosborrego »

Hello,

I would like to color the horizontal lines of the algorithm environment from the algorithms package. Is there a way I can do this?


Thanks so much!
Carlos

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

algorithms | Colored horizontal Lines for Algorithms

Post by localghost »

Does the algorithms manual give no hints for customization?


Best regards and welcome to the board
Thorsten
carlosborrego
Posts: 6
Joined: Sun Dec 09, 2012 1:45 pm

Re: algorithms | Colored horizontal Lines for Algorithms

Post by carlosborrego »

Thanks Thorsten,
No, unfortunately it does not.
Thank you very much
Carlos
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

algorithms | Colored horizontal Lines for Algorithms

Post by localghost »

As I found out in the meantime, the »algorithm« package from algorithms relies on the float package to style the algorithm environment. So it would be necessary to do modifications to those mechanisms. At the moment I have no idea how.
carlosborrego
Posts: 6
Joined: Sun Dec 09, 2012 1:45 pm

Re: algorithms | Colored horizontal Lines for Algorithms

Post by carlosborrego »

Thanks so much localghost, but I am not able to find any information about it in the float manual page. Any other ideas?
Thanks
Carlos
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

algorithms | Colored horizontal Lines for Algorithms

Post by cgnieder »

One could define a new floatstyle and restyle the algorithm float:

Code: Select all

\documentclass{article}
\usepackage{algorithmic,algorithm}
\usepackage{xcolor}

\makeatletter
% this is a copy of the original \fs@ruled but with {\color{blue} ... } added:
\newcommand\fs@coloruled{\def\@fs@cfont{\bfseries}\let\@fs@capt\floatc@ruled
  \def\@fs@pre{{\color{blue}\hrule height.8pt depth0pt }\kern2pt}%
  \def\@fs@post{\kern2pt{\color{blue}\hrule}\relax}%
  \def\@fs@mid{\kern2pt{\color{blue}\hrule}\kern2pt}%
  \let\@fs@iftopcapt\iftrue}
\makeatother

% now use the new style:
\floatstyle{coloruled}
\restylefloat{algorithm}

\begin{document}

% let's see if it works:
\begin{algorithm}
 \caption{Calculate $y = x^n$}
 \label{alg1}
 \begin{algorithmic}
 \REQUIRE $n \geq 0 \vee x \neq 0$
 \ENSURE $y = x^n$
 ...
 \end{algorithmic}
\end{algorithm}

\end{document}
Regards

BTW: the documentation of the algorithms bundle could mention somewhere that its packages are called »algorithm« and »algorithmic« and that one needs to load both...
site moderator & package author
carlosborrego
Posts: 6
Joined: Sun Dec 09, 2012 1:45 pm

Re: algorithms | Colored horizontal Lines for Algorithms

Post by carlosborrego »

Thank you very much! Works like a charm!
Carlos
Post Reply