2

I have a graph plotted in tikz using different line styles for different couplings involved and would like to add a legend for these line styles to the caption. As I am setting all my legends into the caption of the according figure, the layout is then consistent. So adding the legend to the tikzpicture itself is an option, but the last...

The code compiles and I get the desired result, however, although I protect the tikz macro in the caption I receive an error message (I replaced the pointy brackets around "argument" as it is understood as html otherwise):

! Undefined control sequence. --argument-- ... and an arrow \protect \tikz {\draw [prod] (0,0) -- (1,0.2);} ... l.27 and some more text for explanation}

Where does that error come from? Maybe I don't need to worry about it, but trying to understand these things has never been wrong so far ;). Here is the MWE:

\documentclass[11pt,a4paper,sans]{article}
\usepackage{amsmath}
\usepackage{color}
\usepackage{tikz}
\usetikzlibrary{arrows,positioning} 
\tikzset{
    %Define standard arrow tip
    >=stealth',
    % Define arrow style
    prod/.style={
            ->,
            thick, 
            shorten <=2pt,
            shorten >=2pt}
}

\begin{document}

\begin{figure}
    \begin{tikzpicture}[node distance=1cm, auto]
        \path( 0  , 0  ) node(meanu) {$u$}
             ( 2  , 0  ) node(buoy)  {$\mathcal{B}$};
        \draw[prod] (buoy)  --   (meanu);
    \end{tikzpicture}
    \caption{some text and an arrow 
        \protect\tikz{\draw[prod] (0,0) -- (1,0.2);} 
        and some more text for explanation}
\end{figure}

\end{document}
2

Your question is duplicate to adding-tikz-figure-in-caption

In your case:

\documentclass[11pt,a4paper,sans]{article}
\usepackage{amsmath}
%\usepackage{color}
\usepackage{tikz}
\usetikzlibrary{arrows,positioning}
\tikzset{
    %Define standard arrow tip
    >=stealth',
    % Define arrow style
    prod/.style={
            ->,
            thick,
            shorten <=2pt,
            shorten >=2pt}
            }

\begin{document}

\begin{figure}
    \begin{tikzpicture}[node distance=1cm, auto]
        \path(0,0) node (meanu) {$u$}
             (2,0) node (buoy)  {$\mathcal{B}$};
        \draw[prod] (buoy)  --   (meanu);
    \end{tikzpicture}
\caption{Some text and an arrow
        \protect\tikz\protect\draw[prod] (0,0) -- (1,0.2);
        and some more text for explanation}
\end{figure}

\end{document}

enter image description here

  • and I even read that answer but did not see the second \protect.... Thanks :) – Martin Feb 2 '17 at 20:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.