By default, pgfplots seems to add legend entries row-wise. However, I've plot where I'd like a two-column legend (16 curves) and the first 8 entries to be added to the first column before starting the second column. Gnuplot has this behaviour by default, but I can't control the legend style as well as in pgfplots. My code is shown below. Can anyone help me?
\documentclass[landscape]{article}
\usepackage{pgfplots}
\begin{document}
\pgfplotsset{
legend style={%
at={(.99,0.99)},
anchor=north east,
legend columns=2,
font=\footnotesize,
},
width=16.18cm,height=6.18cm,
xmin=0,xmax=100.01,
ymin=0,ymax=8,
xtick={0,10,...,100},
ytick={0,2,...,8},
xlabel={\large Downstream distance, $x$/[cm]},
ylabel={\large Height profile, $h(x,t)$/[cm]},
grid=major,
}
\begin{tikzpicture}
\begin{axis}
\addplot gnuplot [id=p1] {07-09-14/t_0.25.dat u 1:2};
\addplot gnuplot [id=p2] {07-09-14/t_0.5.dat u 1:2};
\addplot gnuplot [id=p3] {07-09-14/t_0.75.dat u 1:2};
\addplot gnuplot [id=p4] {07-09-14/t_1.dat u 1:2};
\addplot gnuplot [id=p5] {07-09-14/t_1.25.dat u 1:2};
\addplot gnuplot [id=p6] {07-09-14/t_1.5.dat u 1:2};
\addplot gnuplot [id=p7] {07-09-14/t_1.75.dat u 1:2};
\addplot gnuplot [id=p8] {07-09-14/t_2.dat u 1:2};
\addplot gnuplot [id=p9] {07-09-14/t_2.25.dat u 1:2};
\addplot gnuplot [id=p10] {07-09-14/t_2.5.dat u 1:2};
\addplot gnuplot [id=p11] {07-09-14/t_2.75.dat u 1:2};
\addplot gnuplot [id=p12] {07-09-14/t_3.dat u 1:2};
\addplot gnuplot [id=p13] {07-09-14/t_3.25.dat u 1:2};
\addplot gnuplot [id=p14] {07-09-14/t_3.5.dat u 1:2};
\addplot gnuplot [id=p15] {07-09-14/t_3.75.dat u 1:2};
\addplot gnuplot [id=p16] {07-09-14/t_4.dat u 1:2};
\legend{{$t=0.25$ s},{$t=0.5$ s},{$t=0.75$ s},{$t=1$ s},{$t=1.25$ s},{$t=1.5$ s},{$t=1.75$ s},{$t=2$ s},{$t=2.25$ s},{$t=2.5$ s},{$t=2.75$ s},{$t=3$ s},{$t=3.25$ s},{$t=3.5$ s},{$t=3.75$ s},{$t=4$ s}};
\end{axis}
\end{tikzpicture}
\end{document}
transposed legendoption (or something like that) which might fit your needs – Christian Feuersänger Jun 28 '12 at 15:51