I know how to create a legend in a pgfplots plot. See
and
Using a pgfplots-style legend in a plain-old tikzpicture.
But I do not know how I can create a legend with two columns.
I know how to create a legend in a pgfplots plot. See
and
Using a pgfplots-style legend in a plain-old tikzpicture.
But I do not know how I can create a legend with two columns.
Simply set the key legend columns=2.
Depending on what you need, you might also be interested in transpose legend and/or reverse legend.
EDIT:
in order to customize the legend's appearance, you can use legend style={<option list>} where <option list> can be any option which applies to a PGF \matrix. All these options can be found in the PGF manual. The one which is necessary here is the column sep key. We have to restrict it to the second column (unless we also want to customize the column separation between images and text).
Here is an example:
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.6}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
legend columns=2,
legend style={
% the /tikz/ prefix is necessary here...
% otherwise, it might end-up with `/pgfplots/column 2`
% which is not what we want. compare pgfmanual.pdf
/tikz/column 2/.style={
column sep=5pt,
},
},
]
\addplot {x};
\addlegendentry{$x$}
\addplot {x+4};
\addlegendentry{$x$+4}
\end{axis}
\end{tikzpicture}
\end{document}

This is a very old question but in case anyone else stumbles upon this I find it far easier to just add whitespace directly into the labels in question using "~".
Like this:
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.6}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
legend columns=2
]
\addplot {x};
\addlegendentry{$x$~~~~}
\addplot {x+4};
\addlegendentry{$x$+4~~~~~}
\end{axis}
\end{tikzpicture}
\end{document}
\multicolsenvironment inside your legend code? – Thanos Nov 03 '12 at 10:00\addlegendimages in a\multicolsenvironment like\begin{multicols}{2} \addlegendimage \addlegendimage \addlegendimage \end{multicols}– Thanos Nov 03 '12 at 10:17