I want to add my legend inside the caption, similarly the one given in this question. But I want to use gnuplot environment as in the following MWE. Unfortunately, I am getting '??' because \label{test} is not working. Is it possible to do that using 'gnuplot' environment? Or one given by @pluton, is this the only way?
My MWE which I am working on it:
\documentclass[12pt,a4paper,english]{article}
\usepackage{lmodern}
\usepackage{lipsum}
\usepackage{caption}
\usepackage{pgfplots}
\usepackage{tikz}
\usepackage{gnuplot-lua-tikz}
\usepackage[shell]{gnuplottex}
\begin{document}
\begin{figure}[!ht]
\centering
\captionsetup{width=9.5cm}
\begin{tikzpicture}
\draw [draw=none,use as bounding box] (0cm,0cm) rectangle (14cm,8cm);{
\begin{gnuplot}[terminal=tikz,terminaloptions={size 14cm, 8cm}]
plot sin(x) w lines t 'sin(x)',\
cos(x) w lines t 'cos(x)'
\label{test} %gives '??' on the pdf, not working
\end{gnuplot}
};
%\addlegendentry{Legend for only desired lines} % Did not work
\node[draw=none, text width=1cm] at (-5.0,1.0) {$sin(x)$}; %this has no sample
\end{tikzpicture}
\caption[Caption in ToC]{This is a plot about colored curves: \ref{test}}
\end{figure}
\end{document}
Thanks for the comments, I am able get what I want.
MVE2 (It creates a legend in \caption)
\documentclass[12pt,a4paper,english]{article}
\usepackage{lmodern}
\usepackage{lipsum}
\usepackage{caption}
\usepackage{pgfplots}
\usepackage{tikz}
\usepackage{gnuplot-lua-tikz}
\usepackage[shell]{gnuplottex}
\begin{document}
\begin{figure}[!ht]
\centering
\captionsetup{width=9.5cm}
\begin{tikzpicture}
\draw [draw=none,use as bounding box] (0cm,0cm) rectangle (14cm,8cm);{
\begin{gnuplot}[terminal=tikz,terminaloptions={size 14cm, 8cm}]
set style line 1 lc rgb "black" lt 1 lw 1 pointinterval 1 pt 1
set style line 11 lc rgb "black" lt 1 lw 5 pointinterval 5 pt 12
plot sin(x) w lines ls 1 t 'sin(x)',\
cos(x) w lines ls 11 t 'cos(x)'
\end{gnuplot}
};
\node[draw=none, text width=1cm] at (-5.0,1.0) {$sin(x)$}; %this has no sample
\end{tikzpicture}
\caption[Caption in ToC]{
\begin{tikzpicture}[baseline=-.5ex,line join=round,line cap=round,color=black]
%First legend
\pgfsetlinewidth{1\gpbaselw}
\node[draw=none, text width=1cm] at (0.0,0.0) {$sin(x)$}; %this has no sample
\draw (0.75,0) -- (1.10,0);
%Creat following legend
\pgfsetlinewidth{5\gpbaselw}
\node[draw=none, text width=1cm] at (1.8,0.0) {$cos(x)$}; %this has no sample
\draw (2.5,0) -- (2.85,0);
\end{tikzpicture}
}
\end{figure}
\end{document}
Aim of the work

\begin{tikzpicture}[baseline=-.5ex,line join=round,line cap=round,color=gnu2]\pgfsetlinewidth{2\gpbaselw}\draw (0,0) -- (0.35,0);\end{tikzpicture})in the caption. Note thatgnu2is a custom defined colour (of course you can also choose one of the predefined colors) and the number before\gpbaselwshould match the linewidth (lw) used in gnuplot. I used this method for one plot in my masters thesis, so this is quite feasible I'd guess. – John Sep 17 '14 at 13:13latexmk -f -pdf -pdflatex="pdflatex -interactive=nonstopmode -shell-escape" -use-make myDoc.texSo, yes I run it twice.\labelis not indicating anything. It is trying put legend inside the caption. I will have look saveboxes, I have no idea about them for now.@John
- I used your advice, it is working, thanks. I can not really say that it is a clear solution, but it works nicely :) I will keep improving my Q/A if I/Someone will come up with better idea. Still, maybe the best is just using
– trblnc Sep 17 '14 at 15:10\addplotas in the linked question.\usepackage{siunitx}to the preamble and change\usepackage[shell]{gnuplottex}to\usepackage[shell,siunitx]{gnuplottex}. Also it is preferable to use$\sin(x)$instead of$sin(x)$(the same is true for cos(x) as well). – John Sep 17 '14 at 15:25