# How to put a \pgfuseshading object inside a caption

I would like to put a pgf object, \pgfuseshading{}, inside the caption of a figure or table. The below code creates this pgf object which can be created in in the text (\pgfuseshading{CyanToBlue}) of the document but causes errors when put inside the caption (\caption {\pgfuseshading{spectrumRedToBlue}}).

Any help putting this pgf object in the caption of the table would be hugely appreciated.

Thank you

\RequirePackage[l2tabu, orthodox]{nag}

\documentclass[a4paper,10pt]{report}

\usepackage{color}
\usepackage[usenames,dvipsnames,svgnames,x11names]{xcolor}

\usepackage{pgf}

color(0.15cm)=(Orange);
color(0.25cm)=(Yellow);
color(0.35cm)=(SpringGreen);
color(0.45cm)=(Cyan);
color(0.65cm)=(Blue)}

\begin{document}

\begin{table}
\begin{center}

\begin{tabular}{l c c c }
\hline\hline
Atom & x ($\AA{}$) & y ($\AA{}$) & z ($\AA{}$) \\ \hline
C & -0.32   & -0.878  & -0.7512 \\

\hline\hline
\end{tabular}

\end{center}
\label{tab:}
\end{table}

\end{document}


You could use \protect ...

\caption{Geometry \protect\pgfuseshading{spectrumRedToBlue}}


... to get:

How it works is nicely described in What is the difference between Fragile and Robust commands?. But then it will also appear in the table of content. See for an other solution to a similar problem Placing graphics inside figure captions. So if it should not appear in toc you could use \caption[Geometry]{Geometry \pgfuseshading{spectrumRedToBlue} or \pgfuseshading{CyanToBlue}} instead.

MWE:

\documentclass{report}
\usepackage[svgnames]{xcolor}
\usepackage{pgf}
color(0.15cm)=(Orange);color(0.25cm)=(Yellow);color(0.35cm)=(SpringGreen);
color(0.45cm)=(Cyan);color(0.65cm)=(Blue)}
\begin{document}
\begin{table}
Atom & x ($\AA{}$) & y ($\AA{}$) & z ($\AA{}$) \\ \hline