I use legend style={legend columns=*} to create columns in my pgfplots legends. However, this options only changes the way legend entries are displayed. What I often need is to display various data for each plot, like in a table. Here is an example of the (ugly) work-around I use so far:
\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
title={$y=a \cdot x + b$},
xlabel=$x$,
ylabel=$y$,
legend pos=south east,
legend style={legend columns=2},
]
\addlegendimage{empty legend}
\addlegendimage{empty legend}
\addlegendentry{$\quad a \quad$} % \quad are just here to make columns wider... I suppose there's a better way
\addlegendentry{$\quad b \quad$}
\addplot+[domain=-1:2, samples=10] {3*x+1};
\addlegendimage{empty legend}
\addplot+[domain=-1:2, samples=10] {2*x+2};
\addlegendimage{empty legend}
\addplot+[domain=-1:2, samples=10] {1*x+3};
\addlegendimage{empty legend}
\addlegendentry{3} % first data for the first graph
\addlegendentry{1} % second data for the first graph
\addlegendentry{2} % first data for the second graph
\addlegendentry{2} % you've got it...
\addlegendentry{1}
\addlegendentry{3}
\end{axis}
\end{tikzpicture}
\end{document}
I'd be grateful for any ideas to make the syntax cleaner and, above all, robust!


\addlegendimage{*}in my legends. With your method, I'd define a\legendimageby hand, mark it with a\labeland call it in the matrix with\ref. Any ideas to make more straight foward? – user122824 Jan 12 '17 at 07:51line legend(have a look in the PGFPlots manual how it is defined and adapt it) and then just use this legend later in the corresponding\addplots. If I misunderstood your question, please just ask a follow-up question illustrating a bit more with an example. – Stefan Pinnow Jan 12 '17 at 08:01nodeandtabularinstead ofmatrix. Sounds like this question was a duplicate, with a more explicit title! – user122824 Jan 12 '17 at 14:25