One could find a lot of questions on how to change the horizontal spacing between legend entries in pgfplots, but I can't find anything on the vertical spacing between the entries.
For example, when I change the legends font size to something smaller than the axis font size, I'd also like to have a thinner vertical spacing between the entries.
MWE:
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
legend style={
cells={anchor=west},
draw=none, fill=none,
font=\scriptsize,
legend pos= north west,
},]
\addplot[blue]{x};
\addplot[red]{2*x};
\legend{$x$,$2x$}
\end{axis}
\end{tikzpicture}
\end{document}
I thought something like
legend style={itemsep = 0.5pt}
could do the trick, but the pgfplots manual remains silent on this point.
Best Answer
You were almost there. Since the pgfplots legend is a
matrix
, you don't have "items" like with a list, rather rows and columns, so adding the following command does the trick:Output
Code