As demonstrated by @Jake in pgfplots: Legends in multiple y-axis plot overlapping you can use \addlegendimage{<plot options>}
before your plot.
For example
\addlegendimage{red,dashed};
\addlegendentry{Different!};
\addplot[blue,thick]{x^2};
gives
MWE
\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addlegendimage{red,dashed};
\addlegendentry{Different!};
\addplot[blue,thick]{x^2};
\end{axis}
\end{tikzpicture}
\end{document}
Update following the comments
If you want a global change, then perhaps something like
\pgfplotsset{every axis/.append style={
legend style={font=\tiny,line width=.5pt,mark size=.6pt},
}}
will be appropriate.
Or, finally, thanks to the guru @Jake, you could try
\pgfplotsset{every axis/.append style={
legend style={ font=\tiny, mark options={scale=0.5} }, }
Do you really need this for every node from every TikZ-picture? Your approach is quite harsh.
Please have a look on my MWE and see, if this is feasable for you.
Off-topic: You have been loading TikZ for three times. \documentclass[tikz]{standalone}
, \usepackage{tikz}
, and \usepackage{tikz-cd}
which loads it as well.
% arara: pdflatex
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\pgfplotsset{%
,tick label style = {font=\sffamily} % see http://tex.stackexchange.com/a/33329 if also needed for numbers.
,every axis label = {font=\sffamily}
,legend style = {font=\tiny\sffamily}
,label style = {font=\sffamily}
}
\begin{document}
\begin{tikzpicture}%
\begin{axis}
\addplot coordinates {(0,0) (1,1) (2,1) (3.5, -1)};
\addlegendentry{Test}
\end{axis}%
\end{tikzpicture}%
\end{document}
The problem with your approach was that you have been using the option font
twice. Once you use font=\sffamily
and once font=\tiny
. You are using the .append style
macro, but this will append the whole option to your drawing. If an option is set twice, TikZ will take the last occurrence.
If you need to set all nodes in your document to \sffamily
, you will have to define your own options such as fontsize=
and fontfamily=
(maybe already existing) or you define a real "font append" as you have been trying to do. This will look like the following (credits to Henry DeYoung):
% arara: pdflatex
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\makeatletter
\tikzset{%
,font append/.style={font/.expand once=\tikz@textfont #1}
,font append/.value required
}
\makeatother
\tikzset{every node/.append style={font append=\sffamily}}
\begin{document}
\begin{tikzpicture}%
\begin{axis}[%
legend style={font=\tiny}
]
\addplot coordinates {(0,0) (1,1) (2,1) (3.5, -1)};
\addlegendentry{Test}
\end{axis}%
\end{tikzpicture}%
\end{document}
Both MWEs result in:
Best Answer
Something like:
The "style"
nodes
of the legend will be applied to all the nodes created to generate the legend box.(BTW, you should add a
\pgfplotsset{compat=1.9}
to your code, or at least something like that, to avoid problems with ticks labels in the future).Complete code (for reference):