## LaTeX forum ⇒ Text Formatting ⇒ Use of Color in Sub-Figure Caption

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
alanaj5
Posts: 3
Joined: Thu Oct 13, 2011 4:57 pm

### Use of Color in Sub-Figure Caption

Hi

I wonder if you can help me.
I'm trying to use \textcolor in the caption of a subfigure, but it keeps throwing an error.

!Argument of \@subfloat has an extra }.

Any way to make text appeared coloured in the subfigure caption would be of great help.

I have \usepackage{color} together with
\begin{figure}   \subfigure[Observations \textcolor{red}{$\mathbf{y}_j$}.]{     \includegraphics[scale=0.8]{obs1.png}   }   \subfigure[An estimate \textcolor{blue}{$\mathbf{X}_b$}.]{     \includegraphics[scale=0.8]{background1.png}   }\end{figure}

If I take out the \textcolor commands, the figures compile perfectly. I also use \textcolor outside of the subfigure captions and that compiles fine for the same colours.

I don't know what I should be using to have coloured text in the caption of a subfigure.

Many thanks for any help.

localghost
Site Moderator
Posts: 9204
Joined: Fri Feb 02, 2007 12:06 pm
It seems that you use the obsolete subfigure package [1]. To clarify that please submit a minimal example. Nevertheless you should about using one of the suggested alternatives [1]. It's not guaranteed that the problem then will disappear. A code example to look at will be helpful.

[1] View topic: Obsolete packages and document classes — Avoid usage!

Best regards and welcome to the board
Thorsten
LaTeX Community Moderator

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1

alanaj5
Posts: 3
Joined: Thu Oct 13, 2011 4:57 pm
Thanks localghost, I am using the obsolete package subfigure.

I have since changed it to the package \usepackage{subfig} as you suggested and changed all my \subfigure to \subfloat. However I now get an error reading

\renewcommand\@makecaption [2]{%

which was a known error when using beamer http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=389467, which appears to have been fixed. Would I just need to update my packages to ones containing the fix in order to get it to compile correctly?

I read something about needing \usepackage{caption2} as well. Do I need this to fix it?

localghost
Site Moderator
Posts: 9204
Joined: Fri Feb 02, 2007 12:06 pm
alanaj5 wrote:[…] Would I just need to update my packages to ones containing the fix in order to get it to compile correctly? […]

That is very likely.
alanaj5 wrote:[…] I read something about needing \usepackage{caption2} as well. Do I need this to fix it? […]

This information is wrong. So forget that. Just use the caption package.
LaTeX Community Moderator

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1

sommerfee
Posts: 500
Joined: Mon Apr 09, 2007 4:20 pm
alanaj5 wrote:However I now get an error reading

\renewcommand\@makecaption [2]{%

What document class are you using? Are you using the beamer document class or a different one?

alanaj5
Posts: 3
Joined: Thu Oct 13, 2011 4:57 pm
I'm using beamer and the beamerposter package.

LexConstantine
Posts: 1
Joined: Fri Aug 23, 2019 5:45 pm
Hi, it may be too late to provide this answer... But I was having this exact issue and figured out that the solution was to protect the caption like so:
\subfigure[Observations \protect\textcolor{red}{$\mathbf{y}_j$}.]{\includegraphics[scale=0.8]{obs1.png}