Change label caption color of a single figure
In my point of view \captionsetup{labelfont={color=blue}}
etc. in the local environment is sufficient:
\documentclass[12pt,twoside]{report}
\usepackage{xcolor}
\usepackage[labelfont={color=red}]{caption}
\begin{document}
\chapter{Test chapter}
\clearpage
\begin{figure}
\captionsetup{labelfont={color=blue}}
A
\caption{Test figure A}
\end{figure}
\begin{figure}
B
\caption{Test figure B}
\end{figure}
\end{document}
Here's a start. For the caption itself, you could do as the comments suggest and place a \textcolor
in the \caption
argument. The number (like "1.2" is contained in \thefigure
, while the descriptor word "Figure" is kept in \figurename
.
kolygr correctly points out that I don't really need to renew \thefigure
, because the color change applied before \figurename
will carry through. I will leave the code as is though, in case one gets ideas about changing \figurename
and \thefigure
to two separate colors.
\documentclass[12pt,twoside]{report}
\usepackage{xcolor}
\usepackage{caption}
\usepackage{caption}
\let\svthefigure\thefigure
\let\svfigurename\figurename
\newcommand\figcolor[1]{%
\renewcommand\thefigure{\bfseries\sffamily\color{#1}\svthefigure}
\renewcommand\figurename{\bfseries\sffamily\color{#1}\svfigurename}
}
\begin{document}
\chapter{Test chapter}
\begin{figure}
\centering
A
\caption{Test figure A}
\end{figure}
\begin{figure}
\figcolor{blue}
\centering
B
\caption{Test figure B}
\end{figure}
\begin{figure}
\centering
B
\caption{Test figure B}
\end{figure}
\end{document}
kolygr also points out that the above code will retain the color in \ref
attributes. That can be avoided by storing the figure markup in a separate markup macro, and \protect
ing it so that the expansion (with color) doesn't get written to the aux
file:
\documentclass[12pt,twoside]{report}
\usepackage{xcolor}
\usepackage{caption}
\usepackage{caption}
\let\svthefigure\thefigure
\let\svfigurename\figurename
\renewcommand\thefigure{\protect\myfigmarkup\svthefigure}
\renewcommand\figurename{\protect\myfigmarkup\svfigurename}
\let\myfigmarkup\relax
\newcommand\figcolor[1]{%
\def\myfigmarkup{\bfseries\sffamily\color{#1}}%
}
\begin{document}
In Figure~\ref{fg1.2}...
\chapter{Test chapter}
\begin{figure}
\centering
A
\caption{Test figure A}
\end{figure}
\begin{figure}
\figcolor{blue}
\centering
B
\caption{Test figure B}
\label{fg1.2}
\end{figure}
\begin{figure}
\centering
B
\caption{Test figure B}
\end{figure}
\end{document}