# Adding tikz figure in caption

I am writing one long document using lyx. I wanted to add small tikz code within a caption of a figure of my document. However when I tried to run it it is giving following error. Please help me resolve this problem.

! Use of \use@pgfplotslibrary doesn't match its definition.
\pgfutil@ifnextchar ...1\def \pgfutil@reserved@a {
#2}\def \pgfutil@reserved@...
l.1411 ... method \label{fig:Velocity-curves-for}}


Here is the code portion

 \documentclass{svmono}
\usepackage{mathptmx}
\renewcommand{\familydefault}{\rmdefault}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{color}
\usepackage{float}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{esint}

\makeatletter

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
\DeclareRobustCommand{\greektext}{%
\fontencoding{LGR}\selectfont\def\encodingdefault{LGR}}
\DeclareRobustCommand{\textgreek}[1]{\leavevmode{%
\IfFileExists{grtm10.tfm}{}{\fontfamily{cmr}}\greektext #1}}
\DeclareFontEncoding{LGR}{}{}
\DeclareTextSymbol{\~}{LGR}{126}
\newcommand{\lyxmathsym}[1]{\ifmmode\begingroup\def\b@ld{bold}
\text{\ifx\math@version\b@ld\bfseries\fi#1}\endgroup\else#1\fi}

%% Because html converters don't know tabularnewline
\providecommand{\tabularnewline}{\\}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\usepackage {tikz,pgfplots}
\usepgfplotslibrary{colormaps}

\@ifundefined{showcaptionsetup}{}{%
\PassOptionsToPackage{caption=false}{subfig}}
\usepackage{subfig}
\makeatother
\begin{document}
\begin{figure}

\centering{}\caption{Velocity curves of the vehicle for 1$^{st}$ scenario. (a) DWA.       \tikz[baseline]\draw[dashed,thick, color = blue](0ex,0ex)--(1ex,0ex);(b)
The proposed method \label{fig:Velocity-curves-for}}
\end{figure}
\end{document}


You need to "protect" the TikZ picture if you are going to use it in section headings or figure captions.

Change

\tikz[baseline]\draw[dashed,thick, color = blue](0ex,0ex)--(1ex,0ex);


to

\protect\tikz[baseline]\protect\draw[dashed,thick, color = blue](0ex,0ex)--(1ex,0ex);