[Tex/LaTex] Plot legend without line break

legendpgfplots

I am having a plot with legend entries. The entries are not really long, it would be nice to have them in a single row. The default behavior adds a line break after each entry. Furthermore, the are all centered, I would prefer left flushed.

I did not find the correct parameter for changing that. Anyone any suggestions or pointers fore me?

Best Answer

You can use the legend columns key (-1 makes all legends to go horizontally):

\documentclass{article}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\pgfplotsset{every axis legend/.append style={
at={(0.5,1.03)},
anchor=south}}
\begin{axis}[legend columns=-1]
\addplot coordinates {(0,0) (1,1)};
\addplot coordinates {(0,1) (1,2)};
\addplot coordinates {(0,2) (1,3)};
\legend{$l_1$,$l_2$,$l_3$}
\end{axis}
\end{tikzpicture}

\end{document}

enter image description here