Text FormattingUse of Color in Sub-Figure Caption

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

Use of Color in Sub-Figure Caption

Post by alanaj5 »

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

Code: Select all

\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.

Recommended reading 2024:

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

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

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

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

Use of Color in Sub-Figure Caption

Post by localghost »

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
alanaj5
Posts: 3
Joined: Thu Oct 13, 2011 4:57 pm

Use of Color in Sub-Figure Caption

Post by alanaj5 »

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?

Thanks for your help.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Use of Color in Sub-Figure Caption

Post by localghost »

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.
User avatar
sommerfee
Posts: 503
Joined: Mon Apr 09, 2007 4:20 pm

Use of Color in Sub-Figure Caption

Post by sommerfee »

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

Re: Use of Color in Sub-Figure Caption

Post by alanaj5 »

I'm using beamer and the beamerposter package.
LexConstantine
Posts: 1
Joined: Fri Aug 23, 2019 5:45 pm

Use of Color in Sub-Figure Caption

Post by LexConstantine »

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:

Code: Select all

\subfigure[Observations \protect\textcolor{red}{$\mathbf{y}_j$}.]{\includegraphics[scale=0.8]{obs1.png}
Hope this helps!
Post Reply