subcaption color with the subfigure package

To define the caption color in my document, I am using

\usepackage{caption}
\usepackage[font={small,color=ocre}]{caption}


Which works perfectly, but currently facing the following two problems:

1. Subcaptions are not colored (I am using the subfigure package, so I can't use the same code as above)

1. When a citation is included in the figure caption , it is not colored.

Does any one have some solutions or hints?

After the request, here is a minimum working example:

\documentclass[a4paper]{article}
\usepackage{amsmath}
\usepackage[numbers,square]{natbib}
%The following is uesd to make the caption colored
\usepackage{xcolor}
\definecolor{ocre}{RGB}{1,160,233}
\usepackage{caption}
\usepackage[font={small,color=ocre}]{caption}
\usepackage{graphicx,subfigure}
\hypersetup{
allcolors=black,
citecolor=black,
}

\usepackage{filecontents}

\begin{filecontents*}{\jobname.bib}
@book{Knu86,
author = {Knuth, Donald E.},
year = {1986},
title = {The \TeX book},
}
\end{filecontents*}

\bibliography{\jobname} % if you’re using BibTeX

\begin{document}

\begin{figure}[hb]
\centering     %%% not \center
\boxed{\subfigure[Subfigure One]{\label{fig:SubfigureOne}\includegraphics[width=0.4\textwidth]{../../Desktop/StackExchange/Test.pdf}}}

\boxed{\subfigure[Subfigure Two]{\label{fig:SubfigureTwo}\includegraphics[width=0.4\textwidth]{../../Desktop/StackExchange/Test.pdf}}}

\caption{Comparison between Subfigure One and Subfigure Two. \autoref{fig:SubfigureOne} shows the difference for the complete data range, and \autoref{fig:SubfigureTwo} as displayed in \cite{Knu86}}
\label{fig:OverAllFigure}
\end{figure}

\end{document}

• Could you show us a fully MWE? – Aradnix Aug 27 '14 at 8:16

Code

\documentclass[a4paper]{article}
\usepackage{amsmath}
\usepackage[numbers,square]{natbib}
%The following is uesd to make the caption colored
\usepackage{xcolor}
\definecolor{ocre}{RGB}{1,160,233}
\usepackage{caption}
\usepackage[font={small,color=ocre}]{caption}
\usepackage{graphicx,subfigure}
\hypersetup{
allcolors=black,
citecolor=black,
}

\usepackage{etoolbox}

\AtBeginEnvironment{figure} {
\hypersetup{
allcolors=ocre,
citecolor=ocre,
}
}

\newcommand{\boxedcolor}[2]{%
\boxed{\color{#1}#2}%
}

\usepackage{filecontents}

\begin{filecontents*}{\jobname.bib}
@book{Knu86,
author = {Knuth, Donald E.},
year = {1986},
title = {The \TeX book},
}
\end{filecontents*}

\bibliography{\jobname} % if you’re using BibTeX

\begin{document}

\begin{figure}[hb]

\centering     %%% not \center
\boxedcolor{ocre}{\subfigure[Subfigure One]{\label{fig:SubfigureOne}\includegraphics[width=0.4\textwidth]{exercises.png}}}

\boxedcolor{ocre}{\subfigure[Subfigure Two]{\label{fig:SubfigureTwo}\includegraphics[width=0.4\textwidth]{exercises.png}}}

\caption{Comparison between Subfigure One and Subfigure Two. \autoref{fig:SubfigureOne} shows the difference for the complete data range, and \autoref{fig:SubfigureTwo} as displayed in \cite{Knu86}}
\label{fig:OverAllFigure}
\end{figure}

Another reference to Figure~\ref{fig:OverAllFigure} with a black hyperling.

\end{document}


Explanation

1. The problem is, that you defined a black color for hyperlinks using \hypersetup. You can change the link colors locally using \hypersetup again at the begin of every figure environment. I think the most comfortable way of doing this is using \AtBeginEnvironment of the package etoolbox.

2. To change the color of the subfigure captions, I defined a new command \boxedcolor. It allows you to change the color inside the box and also affects subfigure captions. Depending on whether you always want to use ocre as you color, you could also define \boxedcolor it with one argument

\newcommand{\boxedcolor}[1]{%
\boxed{\color{ocre}#1}%
}


which leads to shorter usage: \boxedcolor{...}.

Alternatively, you could append \color{ocre} to figure using \AtBeginDocument like I did it with hypersetup before. This would be the most comfortable solution, but it also leads to a colored box (which is not desired, I expect).

What if i'm using subfig package and instead of \boxed I use \subfloat? Here's an example:

\begin{figure}[H]

\centering

\caption{An Example}

\subfloat[\textcolor{white}{Subfigure 1} \label{img:tabuleiro}]{\includegraphics[width=0.30\linewidth]{usual_board_dots_and_squares}} \hspace{2cm}

\subfloat[\textcolor{white}{Subfigure 2} \label{img:tabuleiroInicial}]{\includegraphics[width=0.32\linewidth]{usual_board_dots_and_squares_with_pieces}}

\end{figure}


I want everything in white color, but like in the example above, everything but letters (a) and (b) (which continue to be black) are white. In this case, how can I make everything white?