# Vertical spacing and item separation between entries in pgfplots' legend

One could find a lot of questions on how to change the horizontal spacing between legend entries in , 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,
},]

\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.

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:

legend style={row sep=0.5pt}


## Code

\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,
legend style={row sep=0.5pt}
},]

\legend{$x$,$2x$}