1

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}

\pgfdeclarehorizontalshading{CyanToBlue}{0.25cm}{color(0cm)=(Cyan); color(0.6cm)=(Blue)}                                                                                                                                                   

\pgfdeclarehorizontalshading{spectrumRedToBlue}{0.25cm}{color(0cm)=(Red); 
color(0.15cm)=(Orange);
color(0.25cm)=(Yellow);
color(0.35cm)=(SpringGreen);
color(0.45cm)=(Cyan);
color(0.65cm)=(Blue)} 

\begin{document}

 \pgfuseshading{CyanToBlue} 

\begin{table}
 \caption {Geometry \pgfuseshading{spectrumRedToBlue} }
\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}   
Bobyandbob
  • 4,899
James
  • 25

1 Answers1

3

You could use \protect ...

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

... to get: enter image description here

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}
\pgfdeclarehorizontalshading{CyanToBlue}{0.25cm}{color(0cm)=(Cyan); color(0.6cm)=(Blue)}                                                                                                                                                   
\pgfdeclarehorizontalshading{spectrumRedToBlue}{0.25cm}{color(0cm)=(Red); 
color(0.15cm)=(Orange);color(0.25cm)=(Yellow);color(0.35cm)=(SpringGreen);
color(0.45cm)=(Cyan);color(0.65cm)=(Blue)} 
\begin{document}
\begin{table}
\caption {Geometry \protect\pgfuseshading{spectrumRedToBlue} or  \protect\pgfuseshading{CyanToBlue}  }
%\caption[Geometry]{Geometry \pgfuseshading{spectrumRedToBlue} or \pgfuseshading{CyanToBlue}}
\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}  
Bobyandbob
  • 4,899